-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are getters supported? #1230
Comments
Can you send me a copy of your mapping? |
It's in Kotlin, but those should map to regular Java getters.
|
It decompiles to
|
I've just added a test with your example, and it works: |
the thing is "the member name is taken from its property name equivalent" to me means that for a method named "getTenant" then it would look for a config key "tenant" |
So I'd expect this to work:
|
Sorry, the documentation is not clear. It is always supposed to be the method name because Java interfaces don't define member fields for getters. |
It's very misleading. Why have a separate bullet for getters if there is no special handling for them? I think adding special handling for getters would be nice to allow use of kotlin properties instead of methods |
We discussed this in the very first implementation and decided not to do it: Adding it now may break existent configuration and would require a compatibility mode. @dmlloyd, what do you think about this? |
Maybe we could add it under an annotation? Something that is heritable from the interface to its methods, so you only have to do it once? e.g. |
Or in |
Personally I'd find it most useful to be able to configure it globally via |
I think From there it might be possible to relay it into a global setting on the API, if someone really wanted to do so (I don't recall whether we have such a flag for setting the default naming strategy though). |
Yes, as separate property.
This has been requested in #1091, and I ended up discarding it. It is not trivial to implement because it would require some adjustments to our generator to make the implementation less static. |
hey, that's nice but I'd really like to configure this globally instead of having to write (and potentially forget) this on every config class. Should I open another issue for that? |
Is there some way we can detect that an interface is a Kotlin interface at run time? Maybe we could automatically detect this and avoid having to have a global configuration switch, which brings with it other problems. |
That would cover my current use case I guess the @metadata annotation is one point of detection? OTOH the global switch could be useful in other contexts, e.g. somebody is migrating from Boot's @ConfigurationProperties |
PS. Also I'd be wary about adding to much magical autoconfiguration. Personally I'd rather configure it as a global explicit setting. IMO that's a good price for better clarity. |
Might want to check this out re detecting Kotlin https://github.com/spring-projects/spring-framework/blob/a143b57d4b397f5778428be40cc7a5083c42ee89/spring-core/src/main/java/org/springframework/util/KotlinUtils.java#L50 |
So we'd probably want to do something like: boolean isKotlin = Stream.of(interface_.getDeclaredAnnotations()).anyMatch(i -> i.getClass().getName().equals("kotlin.Metadata")); The only possible issue is that this would return |
I'm not sure ATM if the option implemented in #1239 is exclusive or are plain names also matched? If it's exclusive the enabling it automatically would break existing kotlin usage |
Is Kotlin using a mixture of bean-style names and fluent-style names for getters? |
I understand the inconvenience. Right now, this is the best we can do. Adding a global switch requires a considerable amount of effort. The mapping implementation generation only takes into account the interface metadata. Adding a global switch would require adding config into the mix, plus generating dynamic pieces in the implementation to account for the flag change. Also, in the case of Quarkus, where the implementations are generated during build time, we would either have to fix that configuration or generate the implementation with config awareness so they can adjust to the flag. All doable, sure, but again, requiring a considerable amount of effort.
Even if we add the flag, another mapping in the classpath from a dependency may break with the global behavior, making it useless.
The problem with Kotlin support is that you require deep integration with the Kotlin API, to detect certain constructs. That makes sense, as these constructs are not native to Java. We definitely don't want to introduce Kotlin as a core dependency. From our Quarkus experience, fixing a Kotlin version and having all Kotlin-aware libraries behave correctly is tricky. Ideally, we would need to introduce extension points in a few places to allow having a separate module with the Kotlin integration and have a clear separation. I've discussed this as well here #844 and #1098. As you can imagine, this would also require considerable work. I'm happy to do some of the work, but until now, no one else has volunteered to help and we have been working in other stuff. |
@dmlloyd I mean this is what I would write in kotlin now. If plain names are not supported together with getters autodetecting kotlin would break it
|
@radcortez I wasn't advocating for that. In fact I wrote I'd advise against it. But since @dmlloyd wanted to do it I gave some links to how spring does that |
I'm not a kotlin person so I don't know what you mean. This is why I asked my question: "Is Kotlin using a mixture of bean-style names and fluent-style names for getters?" Normally we just implement the interface directly. Users don't generally implement it. Is that what you're trying to do - implement the interface with some kind of automatic kotlin bean object? |
No, when you write that in kotlin you get a "plain" java interface as expected by smallrye-config The kotlin code above decompiles to this java code:
|
I think they are:
Yet, I can't get them to work, e.g.
I'm using 3.9.1
The text was updated successfully, but these errors were encountered: