castor-data-binding / castor

http://castor-data-binding.github.io/castor/
35 stars 29 forks source link

Disable output escaping does not work using castor default configuration #63

Open kovax opened 7 years ago

kovax commented 7 years ago

I am trying to implement a CDATAFieldHandler, and it works fine except that the string value returned by the getValue() is escaped inthe final marshalled xml. Marshalling is done by this code segment:

    StringWriter sWriter = new StringWriter();
    Marshaller marshaller = mappingContext.createMarshaller();
    marshaller.setWriter(sWriter);
    marshaller.setMarshalAsDocument(false);

    if (obj instanceof Query) marshaller.addProcessingInstruction(Result.PI_DISABLE_OUTPUT_ESCAPING, "");

    marshaller.marshal(obj);
    return sWriter.toString();

mappingContext is an instance of XMLContext initalised at boot time by loading all of our mappings.

My test unmarshalls a hand-written xml and marshalls it back. Unmarshall works, the Object created correctly, but marshaller will convert the string escaped.

I use castor 1.4.1. and JavaSE 1.8

jhaydtw commented 7 years ago

I have a similar issue in 1.3.1 (on Java 7) where my code goes through the trouble to replace apostrophe (') with &apost; while creating a byte array stream, but when I unmarshall the stream into ojbects the encodings are changed back to apostrophes. This is causing the concatenation in the db code to fail.