Skip to content

Instantly share code, notes, and snippets.

@baybatu
Last active July 21, 2016 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baybatu/a184065ddeee8003a0114de2f860b754 to your computer and use it in GitHub Desktop.
Save baybatu/a184065ddeee8003a0114de2f860b754 to your computer and use it in GitHub Desktop.
Add CDATA block into your XML output without escaping in JAXB
JAXBContext jaxbContext = JAXBContext.newInstance(MyClass.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty("com.sun.xml.internal.bind.characterEscapeHandler", new CharacterEscapeHandler() {
                @Override
                public void escape(char[] ac, int i, int j, boolean flag, Writer writer) throws IOException {
                    writer.write(ac, i, j);
                }
            });

Source:http://odedpeer.blogspot.com.tr/2010/07/jaxb-sun-and-how-to-marshal-cdata.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment