Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlMapper is unable to deserialise into an empty record (Java 17) #508

Open
protazy opened this issue Jan 3, 2022 · 0 comments
Open

XmlMapper is unable to deserialise into an empty record (Java 17) #508

protazy opened this issue Jan 3, 2022 · 0 comments

Comments

@protazy
Copy link

protazy commented Jan 3, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant