3 Replies Latest reply on Oct 10, 2013 7:31 AM by arun.parihar

    JAXB Marshalling and Character Escape Hander

    Rod Miller Newbie

      I have a JAX-B annotated class that contains an String element that has the contents of a CDATA section

       

      e.g.

       

      <![CDATA[ SOME CDATA HERE ]]>

       

      When utilising the JAX-B marshalling availible in camel via

       

      JaxbDataFormat jaxbFormatter = new JaxbDataFormat( "location of schema");

       

      from("some URI").marshal(jaxbFormatter);

       

      The output appears as character escaped e.g.:

       

      &lt;![CDATA[SOME CDATA HERE]] ]]&gt;

       

      Previously in plain java I have got round the problem by using a charater escape handler:

       

      JAXBContext context = JAXBContext.newInstance(myClass.class);     

       

      Marshaller marshaller = context.createMarshaller();               

                                          

      // Add an handler to prevent the CDATA section from being removed

      marshaller.setProperty( "com.sun.xml.bind.characterEscapeHandler", new CdataCharacterEscapeHandle());  

       

      java.io.StringWriter sw = new StringWriter();

      marshaller.marshal(alarm, sw);

       

      Is there a mechanism to set properties on the marshaller used in Camel, or is there an alternative sollution that I can utilised in Camel to marshall my CDATA?