You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this setup, explicitly requesting an instance of Size using getValue works fine, as expected since the target type is explicitly passed. However, for the configmap setup, Smallrye will see the size field for its backing type, Long. Then, conversion fails since the converter is defined for Size and not Long. Note that annotating the field with WithConverter 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:
One could force Kotlin to make the field "boxed" by making the value class implement an interface and then setting the configmap field type to be the interface. However, that triggers another issue: Converter for interface type is ignored #931
One could write a custom converter for the backing field type (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.
Not using a value class - which is not always desirable given the overhead of boxing/unboxing a primitive type.
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
SizeusinggetValueworks fine, as expected since the target type is explicitly passed. However, for the configmap setup, Smallrye will see thesizefield for its backing type,Long. Then, conversion fails since the converter is defined forSizeand notLong. Note that annotating the field withWithConverterdoes 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.