Class JSONFormattedWriterRecord

  • All Implemented Interfaces:
    AbstractMarshalRecord<CoreAbstractSession,​CoreField,​XMLMarshaller,​NamespaceResolver>, MarshalRecord<CoreAbstractSession,​CoreField,​XMLMarshaller,​NamespaceResolver>, XMLRecord<CoreAbstractSession>

    public class JSONFormattedWriterRecord
    extends JSONWriterRecord

    Use this type of MarshalRecord when the marshal target is a Writer and the JSON should be formatted with carriage returns and indenting.

    XMLContext xmlContext = new XMLContext("session-name");
    XMLMarshaller xmlMarshaller = xmlContext.createMarshaller();
    JSONFormattedWriterRecord jsonFormattedRecord = new JSONFormattedWriterRecord();
    jsonFormattedWriterRecord.setWriter(myWriter);
    xmlMarshaller.marshal(myObject, jsonFormattedWriterRecord);

    If the marshal(Writer) and setMediaType(MediaType.APPLICATION_JSON) and setFormattedOutput(true) method is called on XMLMarshaller, then the Writer is automatically wrapped in a JSONFormattedWriterRecord.

    XMLContext xmlContext = new XMLContext("session-name");
    XMLMarshaller xmlMarshaller = xmlContext.createMarshaller();
    xmlMarshaller.setMediaType(MediaType.APPLICATION_JSON); xmlMarshaller.setFormattedOutput(true);
    xmlMarshaller.marshal(myObject, myWriter);

    See Also:
    XMLMarshaller