I am trying to parse an XML string to a Java object using fasterxml.jackson.xml.XmlMapper
.
The problem is that the XML string contains the character '&'.
I am getting an exception thrown
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Unexpected character '&' in prolog; expected '<'.
Code
import java.util.Map;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
public class MyProblem {
public static void main(String[] args) {
XmlMapper = xmlMapper = new XmlMapper();
String myXML = "<cookies>Chocolate&Butter cocunut</cookies>";
Map<String, String> myTester = xmlMapper.reader().readValue(myXML, Map.class);
}
}
I was expecting it to work when I perform a System.out.println(myTester);
After reading XmlMapper's documentation, I believe there is a property I can set that I can use to override deserialization functionalities.
If I need to escape these special characters, how to do?