-
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
Support for Kotlin value types #1098
Comments
Yes, unfortunately, to be able to support some of the Kotlin native features, we are required to use specific Kotlin APIs when generating the model. I guess the cleanest way is to duplicate the current generation model and enhance the pieces that Kotlin could benefit from. Having a single model with checks could work as well, but probably harder to maintain. Relates to #844 Is this something you can help with? |
I feel like a clean approach would be to open up some of the classes in the current codebase, so we can write a separate Using custom interceptors, I have been able to at least support properties in config maps, in addition to normal functions. But with better reflection support and closer integration with the rest of the library, this can probably be done much neater and safer. My current approach just tries to strip |
The The generated code is just a call to the programmatic API to create and retrieve each method value. In https://github.com/smallrye/smallrye-config/blob/main/implementation/src/test/java/io/smallrye/config/ObjectCreatorTest.java#L18, you can find handwritten implementations using the same APIs that are used when generating the class so you can have an idea. Probably, we would require a Kotlin module to provide its view of I can do the work to open up these mechanisms and allow them to be replaced by an overriding module. It would be great to get help with the Kotlin pieces since I'm not very proficient with Kotlin. |
Currently, this library does not support Kotlin (inline) value types/classes for a config mapping setup.
For an example, let's consider the following definition:
In this setup, explicitly requesting an instance of
Size
usinggetValue
works fine, as expected since the target type is explicitly passed. However, for the configmap setup, Smallrye will see thesize
field for its backing type,Long
. Then, conversion fails since the converter is defined forSize
and notLong
. Note that annotating the field withWithConverter
does not work - Smallrye will throw an error that the types do not match.I am afraid this is not a very easy fix: it seems like special, Kotlin-specific, reflection APIs are needed to find the "actual" value class type. For example, Jackson does not yet support this in mainline and has a separate experimental library to implement it: https://github.com/ProjectMapK/jackson-module-kogera
There do seem to be a few workarounds at the moment:
Long
), but then this converter cannot be auto-discovered to prevent conflicts with normal uses of that backing type. Consequently, each configmap field needs to be annotated by hand.The text was updated successfully, but these errors were encountered: