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
Can I deserialize a data class with an unsigned member in the constructor?
Jackson 2.13.4
I am working with some unsigned numbers and I know that I will be deserializing incoming json. I would like to directly map the numbers to their unsigned representation. I checked #525 and #524 and upgraded to 2.13.4
I am seeing an error that does not make sense
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of A (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
My simplified model clearly has a no-arg constructor (like all my other data classes that do work)
data classA(
vara:String = "",
varb:ULong = 0U,
)
Am I doing something wrong? Is this a bug?
My test case:
classDataClassConstructorWithUnsignedTest {
@Test
funa() {
val a1 =A()
val mapper = jacksonObjectMapper()
val serialized = mapper.writeValueAsString(a1)
.also(::println)
assertDoesNotThrow {
val deserialized = mapper.readValue(serialized, A::class.java)
.also(::println)
}
}
}
Stack trace
org.opentest4j.AssertionFailedError: Unexpected exception thrown: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `A` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (String)"{"a":"","b":0}"; line: 1, column: 2]
at DataClassConstructorWithUnsignedTest.a(DataClassConstructorWithUnsignedTest.kt:17)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `A` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (String)"{"a":"","b":0}"; line: 1, column: 2]
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1904)
at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:400)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1349)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1415)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:351)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:184)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:322)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4674)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3629)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3597)
at DataClassConstructorWithUnsignedTest$a$1.invoke(DataClassConstructorWithUnsignedTest.kt:19)
The text was updated successfully, but these errors were encountered:
Can I deserialize a data class with an unsigned member in the constructor?
Jackson 2.13.4
I am working with some unsigned numbers and I know that I will be deserializing incoming json. I would like to directly map the numbers to their unsigned representation. I checked #525 and #524 and upgraded to 2.13.4
I am seeing an error that does not make sense
My simplified model clearly has a no-arg constructor (like all my other data classes that do work)
Am I doing something wrong? Is this a bug?
My test case:
Stack trace
The text was updated successfully, but these errors were encountered: