4

I'm trying to convert an object to xml using jackson

XmlMapper xmlMapper = new XmlMapper();
            xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
            xmlMapper.writeValue(createFileResult.getFile(), detailsProductDTOs);

however, because my object somewhere contains invalid character for xml, I get an error. Is there some way to tell jackson to ignore this kind of characters? or any other solution?

Caused by: java.io.IOException: Invalid white space character (0xb) in text to output (in xml 1.1, could output as a character entity)
    at com.ctc.wstx.api.InvalidCharHandler$FailingHandler.convertInvalidChar(InvalidCharHandler.java:56)
    at com.ctc.wstx.sw.XmlWriter.handleInvalidChar(XmlWriter.java:629)
    at com.ctc.wstx.sw.BufferingXmlWriter.writeCharacters(BufferingXmlWriter.java:583)
    at com.ctc.wstx.sw.BaseStreamWriter.writeCharacters(BaseStreamWriter.java:469)
    at com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.writeString(ToXmlGenerator.java:588)
3

1 Answer 1

4

Finally, I solved the problem by myself. As error indicates xml 1.1 supports this kind of characters. So its possible to solve the problem just by adding following configuration:

xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_1_1, true);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.