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
SequenceWriter returns NPE when trying XML serialization.
Version information
2.11.2
To Reproduce
If you have a way to reproduce this with:
ByteArrayOutputStream OUTPUT_STREAM = new ByteArrayOutputStream();
ObjectMapper xmlMapper = new XmlMapper();
SequenceWriter seqWriter = xmlMapper.writer().writeValues(OUTPUT_STREAM);
Map<String, String> reportObject = new HashMap<>();
reportObject.put("a", "b");
seqWriter.write(reportObject);
Expected behavior
Additional context
Stack trace:
java.lang.NullPointerException
at com.fasterxml.jackson.dataformat.xml.util.XmlRootNameLookup.findRootName(XmlRootNameLookup.java:41)
at com.fasterxml.jackson.dataformat.xml.ser.XmlSerializerProvider.serializeValue(XmlSerializerProvider.java:148)
at com.fasterxml.jackson.databind.SequenceWriter.write(SequenceWriter.java:153)
The text was updated successfully, but these errors were encountered:
Since 2.11.2 is neither the latest minor version, nor the latest patch of 2.11 (2.11.4 is that) it would make sense to try this with a more recent version? Ideally 2.12.5 that was just released.
I don't think that will make much difference here but as a general best practice it makes sense.
Note, however that although NPE is unexpected, usage as shown will not work: since XML documents MUST have just ONE ROOT ELEMENT, and as such it is not possible to write root value sequences this way.
This is limitation of XML (and underlying XML generators) more than Jackson.
I realize that in your example the issue is reported for the first value so this particular case might be supportable, but there would be failure for second value.
If you absolutely want to produce such output, you will need to use different approach: use separate writeValue() calls, passing OutputStream.
So something like:
ObjectMapper xmlMapper = new XmlMapper();
ObjectWriter w = xmlMapper.writer()
w.writeValue(out, value1);
w.writeValue(out, value2);
and this would "work" in the sense that separate calls would create separate generators that are unaware of previously written root elements.
Describe the bug
SequenceWriter returns NPE when trying XML serialization.
Version information
2.11.2
To Reproduce
If you have a way to reproduce this with:
Expected behavior
Additional context
Stack trace:
The text was updated successfully, but these errors were encountered: