Can I force JAXB not to convert " into ", for example, when marshalling to XML?

后端 未结 14 1980
情深已故
情深已故 2020-11-29 09:27

I have an Object that is being marshalled to XML using JAXB. One element contains a String that includes quotes (\"). The resulting XML has " where t

14条回答
  •  Happy的楠姐
    2020-11-29 09:39

    I would say that easiest way to do is by overriding CharacterEscapeHandler :

    marshaller.setProperty("com.sun.xml.bind.characterEscapeHandler", new CharacterEscapeHandler() {
        @Override
        public void escape(char[] ch, int start, int length, boolean isAttVal,
                           Writer out) throws IOException {
            out.write(ch, start, length);
        }
    });
    

提交回复
热议问题