I have an XML file which contains an element with special characters or escape characters in it. When I unmarshall this file into a Java object, JAXB automatically escapes these characters. However I do not want them to be escaped and the object should be populated with whatever value is present in the XML file. Snippet of my XML file looks something like this:
<Order>
<name>Order One ></name>
<price>50</price>
<Order>
My JAXB Order class looks like below:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Order")
public class Order{
@XmlElement
private String name;
@XmlElement
private String price;
//skipping getter and setter for brevity
On unmarshalling , Order class object's name field has value "Order one >" whereas I want it to be "Order One >
" as that is the requirement.
I am aware of the solution of putting this value within CDATA so that it doesn't get escaped however the XML file I am unmarshalling is from an outside source and I have no control over the file. I read about a solution on SO where it was suggested of looking for '&' and replacing it. But that solution doesnt look generic and wont apply to all scenarios. Unmarshalling XML with JAXB without unescaping characters
I am new to the world of JAXB and trying to find my feet. What I am trying to do might have been done before but I haven't found a solution for doing it. There are several solutions available on SO about escaping characters with JAXB however almost all talk about marshalling. Any help would be appreciated.