Git Product home page Git Product logo

Comments (10)

cojo avatar cojo commented on June 11, 2024

Before I forget - I'm using Kotlin 1.2.30 and Java 8 / 1.8 if that's helpful or important for whatever reason.

from cfg4k.

jdiazcano avatar jdiazcano commented on June 11, 2024

Taking a look. I'm not sure if inside an enum the DefaultImpls is different or something. Actually that's one of the things that I didn't think of, an enum with methods and default.

from cfg4k.

cojo avatar cojo commented on June 11, 2024

Thanks for taking a look! Yeah that was one thought I had, but what was weird was that it seemed to be failing on this issue in the the base Config class regardless of the enum's involvement as I was testing different things out.

from cfg4k.

jdiazcano avatar jdiazcano commented on June 11, 2024

Ohhh, I think I know what's happening.

An enum class is a real class (not an interface) and it will not have DefaultImpl but real implementations. Let me try it and maybe there's a workaround defining an interface for the Enum.

from cfg4k.

jdiazcano avatar jdiazcano commented on June 11, 2024

Yes, that is exactly what is happening (I'll try to fix it to work with classes anyways though)

enum class TestEnum : Interf {
    TEST, TEST1, TEST2
}

interface Interf {
    val name: String
    val slug: String get() = name.toLowerCase()
}

If you use it like that you won't have any problems

        it("binding test") {
            val testBinder = provider.bind<BindedEnum>("")
            testBinder.thisWillBeEnum().should.be.equal(TestEnum.TEST)
            testBinder.thisWillBeEnum().slug.should.be.equal(TestEnum.TEST.name.toLowerCase())
        }

from cfg4k.

cojo avatar cojo commented on June 11, 2024

I tried stripping out the enum entirely and actually get the same thing:

com.jdiazcano.cfg4k.utils.SettingNotFound: Setting server not found
	at com.jdiazcano.cfg4k.binders.BindingInvocationHandler.invoke(BindingInvocationHandler.kt:65)
	at com.sun.proxy.$Proxy0.getServer(Unknown Source)
	at AppServer.run(AppServer.kt:33)
	at AppServer.main(AppServer.kt:16)

Note for context, that this error setting server not found is a red herring as it is actually swallowing the ClassNotFoundException I mentioned in the original post
image

Any chance there might be two separate issues going on here? One the enum but the other the cause of the original Exception?

from cfg4k.

cojo avatar cojo commented on June 11, 2024

Current code is the same for the server portion, but this is all there is now in the Config.kt file:

interface Config {
    val database: DatabaseConfig
    val server: ServerConfig
}

interface DatabaseConfig {
    val url: String
    val username: String
    val password: String
}

interface ServerConfig {
    val port: Int
    val host: String
    val environment: String
}

from cfg4k.

jdiazcano avatar jdiazcano commented on June 11, 2024

Could you paste also the properties file changing all the strings for something else? It might be related to naming then

And if you want I'm available in kotlin slack.

from cfg4k.

jdiazcano avatar jdiazcano commented on June 11, 2024

So the real issue is that Environment and System loaders right now do not support binding due to the way that it is designed right now.

They still can be used with a normal get<String>("server.host")

from cfg4k.

jdiazcano avatar jdiazcano commented on June 11, 2024

Now both extends DefaultConfigLoader so merges and binding are supported.

The only caveat is that if you try to add value to an already set object a warning will be emitted.

from cfg4k.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.