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
It seems that deserialising into an empty record does not work correctly, however the same example with an "empty" class works just fine.
Here's a snippet of code to reproduce:
package org.example;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
public class App {
public static void main(String[] args) throws JsonProcessingException {
XmlMapper mapper = XmlMapper.builder().build();
// This works just fine, an empty class will deserialise correctly.
EmptyClassTest emptyClassTest = mapper.readValue("<EmptyClassTest/>", EmptyClassTest.class);
// This throws an exception.
EmptyRecordTest emptyRecordTest = mapper.readValue("<EmptyRecordTest/>", EmptyRecordTest.class);
}
public static class EmptyClassTest {
}
public record EmptyRecordTest() {
}
}
After executing the above code, an exception is thrown when trying to deserialise into an empty record:
Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of org.example.App$EmptyRecordTest (although at least one Creator exists): no default no-arguments constructor found
at [Source: (StringReader); line: 1, column: 1]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1728)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1353)
at com.fasterxml.jackson.databind.deser.ValueInstantiator.createUsingDefault(ValueInstantiator.java:248)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createUsingDefault(StdValueInstantiator.java:275)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.getEmptyValue(BeanDeserializerBase.java:1042)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromEmptyString(StdDeserializer.java:322)
at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromString(StdDeserializer.java:270)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1495)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:196)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:186)
at com.fasterxml.jackson.dataformat.xml.deser.XmlDeserializationContext.readRootValue(XmlDeserializationContext.java:91)
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 org.example.App.main(App.java:14)
Tested with jackson-dataformat-xml version 2.13.1
The text was updated successfully, but these errors were encountered:
It seems that deserialising into an empty record does not work correctly, however the same example with an "empty" class works just fine.
Here's a snippet of code to reproduce:
After executing the above code, an exception is thrown when trying to deserialise into an empty record:
Tested with jackson-dataformat-xml version 2.13.1
The text was updated successfully, but these errors were encountered: