I have a Java XML String where the values of some properties are wrapped in <![CDATA ... ]]>. I created a class called Root that I have used to unmarshal the string into an object successfully. I now want to convert it back into the same string (after I changed some values). JAXB.unmarshal(new StringReader(XML), Root.class);
The issue I have is the following:
- The CDATA wrapping is removed from all of the values (the original string had it and I want to keep it when I marshal it back to string from object).
- The header includes standalone attribute, which was not included in the original string (I want it removed and replaced with only version and encoding, as was in the original string).
- I have self closing tags in the original XML string, but they are removed when I am marshalling back into a string.
- Formatting is removed and I get a single line when I marshal. I want it to be formatted.
I am using JAXB 4.0 and Java 17.