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
When trying to deserialize a class that has a constructor with both a value class instance, as well as a non-nullable property with a default value, Jackson won't find the correct constructor and resort to passing null to the non-nullable property.
As is probably known to you, Kotlin will generate a synthetic constructor with extra int, DefaultConstructorMarker parameters to deal with default values, besides the "normal" constructor with all parameters. However, in the specific case that one of the values is also a value class, there is no such "normal" constructor, and it too will have an additional DefaultConstructorMarker. We can see this by listing the constructors for Foo:
public nl.test.Foo(int,java.lang.String,kotlin.jvm.internal.DefaultConstructorMarker)
public nl.test.Foo(int,java.lang.String,int,kotlin.jvm.internal.DefaultConstructorMarker)
Consequently, the Constructor<T>.kotlinFunction call at ReflectionCache.kotlinFromJava returns null, since none of these constructors have a Kotlin function. As a consequence of that, the KotlinValueInstantiator will resort to the normal Java behaviour, calling a default Java constructor with a null value for the nonNullDefault property, resulting in a runtime error/NPE.
Expected behavior
I would expect parsing to succeed, obviously. However, I don't know how best to mitigate the cause of this issue.
As explicitly stated in #650, jackson-module-kotlin does not currently support deserialization of value class.
If you want to try deserialization of value class, please use Kogera. #650
Describe the bug
When trying to deserialize a class that has a constructor with both a value class instance, as well as a non-nullable property with a default value, Jackson won't find the correct constructor and resort to passing
null
to the non-nullable property.To Reproduce
As is probably known to you, Kotlin will generate a synthetic constructor with extra
int, DefaultConstructorMarker
parameters to deal with default values, besides the "normal" constructor with all parameters. However, in the specific case that one of the values is also a value class, there is no such "normal" constructor, and it too will have an additionalDefaultConstructorMarker
. We can see this by listing the constructors forFoo
:Consequently, the
Constructor<T>.kotlinFunction
call atReflectionCache.kotlinFromJava
returnsnull
, since none of these constructors have a Kotlin function. As a consequence of that, theKotlinValueInstantiator
will resort to the normal Java behaviour, calling a default Java constructor with anull
value for thenonNullDefault
property, resulting in a runtime error/NPE.Expected behavior
I would expect parsing to succeed, obviously. However, I don't know how best to mitigate the cause of this issue.
Versions
Kotlin: 1.8.21
Jackson-module-kotlin: 2.15.2
Jackson-databind: 2.15.2
This is probably sideways related to #650
The text was updated successfully, but these errors were encountered: