-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
Describe the bug
This code used to work with 2.14.2, but not with 2.15.0
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
RecordTest recordTest_deserialized = mapper.readValue("{}", RecordTest.class);
Version information
2.15.0
To Reproduce
/**
* This works fine with Jackson 2.14.2, but not with 2.15.0.
*/
public class Jackson_2_15_0_Regression {
record RecordTest(String string, int integer) {
}
@Test
public void emptyJsonToRecord() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
// mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
RecordTest recordTest_deserialized = mapper.readValue("{}", RecordTest.class);
System.out.println("RecordTest deserialized: " + recordTest_deserialized);
Assert.assertEquals(new RecordTest(null, 0), recordTest_deserialized);
}
}
Comment out the mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE)
and it works.
Note that the commented-out mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY)
is included in my actual code to get intended behaviour (i.e. only fields are serialized and deserialized, no methods involved), but this did not make any to or from for the problem.
Exception is:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `io.mats3.examples.jbang.Jackson_2_15_0_Regression$RecordTest` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (String)"{}"; line: 1, column: 2]
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1915)
at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:414)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1360)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1424)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:352)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:185)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4825)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3772)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3740)
at io.mats3.examples.jbang.Jackson_2_15_0_Regression.emptyJsonToRecord(Jackson_2_15_0_Regression.java:25)
Metadata
Metadata
Assignees
Labels
No labels