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
Describe the bug
In case when parameter of the withSerializers() / withDeserializers() call is lambda [() → {}], we have an JsonbException because of ClassCastException in ReflectionUtils.findParameterizedType(ReflectionUtils.java:342).
The reason: lambdas have no runtime information - comparing to the (anonymous) classes. Therefore, Class.getGenericInterfaces() just get us the lambda's implemented interface itself, not the generic interfaces of the implemented class or interface. So we can't cast it and get an exception. And the given class itself has no generic information. So in case of lambdas, we have no chance to get the generic information through the reflection.
To Reproduce
I duplicated the existing two deserializes tests with lambdas instead of the anonymous classes. Of course, this tests asserts the exception now.
Expected behavior
There should be no difference between the deserializer implemented as class, anonymous class or lambda.
Additional context
Because of Java internals, which in case of lambda don't specify how to handle the runtime information of lambdas or specifying to having none, there would be no chance to get this information during the runtime.
I understand, that this means a change in the upstream / implemented API. But I think that this is an issue, which another implementation should also see at this point.
Maybe there are also another solutions.
The text was updated successfully, but these errors were encountered:
Describe the bug
In case when parameter of the withSerializers() / withDeserializers() call is lambda [() → {}], we have an JsonbException because of ClassCastException in ReflectionUtils.findParameterizedType(ReflectionUtils.java:342).
The reason: lambdas have no runtime information - comparing to the (anonymous) classes. Therefore, Class.getGenericInterfaces() just get us the lambda's implemented interface itself, not the generic interfaces of the implemented class or interface. So we can't cast it and get an exception. And the given class itself has no generic information. So in case of lambdas, we have no chance to get the generic information through the reflection.
To Reproduce
I duplicated the existing two deserializes tests with lambdas instead of the anonymous classes. Of course, this tests asserts the exception now.
Expected behavior
There should be no difference between the deserializer implemented as class, anonymous class or lambda.
Additional context
Because of Java internals, which in case of lambda don't specify how to handle the runtime information of lambdas or specifying to having none, there would be no chance to get this information during the runtime.
I can think about one possible solution, which is already used in Gson (see https://www.javadoc.io/static/com.google.code.gson/gson/2.10.1/com.google.gson/com/google/gson/GsonBuilder.html#registerTypeAdapter(java.lang.reflect.Type,java.lang.Object) for example): to have an additional method with directly given type for a serializer / deserializer / adapter (the last isn't important, because adapter can't be implemented with lambda). This way, one don't have to go through reflection to get the generic interface of the parameter's implementation. Because it was already given as another parameter.
I understand, that this means a change in the upstream / implemented API. But I think that this is an issue, which another implementation should also see at this point.
Maybe there are also another solutions.
The text was updated successfully, but these errors were encountered: