Class JSONFormattedWriterRecord

java.lang.Object
org.eclipse.persistence.internal.core.sessions.CoreAbstractRecord
org.eclipse.persistence.internal.oxm.record.AbstractMarshalRecordImpl<org.eclipse.persistence.internal.core.sessions.CoreAbstractSession,org.eclipse.persistence.internal.core.helper.CoreField,MARSHALLER,org.eclipse.persistence.internal.oxm.NamespaceResolver>
org.eclipse.persistence.oxm.record.MarshalRecord<org.eclipse.persistence.internal.oxm.XMLMarshaller>
org.eclipse.persistence.oxm.record.JSONWriterRecord
org.eclipse.persistence.oxm.record.JSONFormattedWriterRecord
All Implemented Interfaces:
org.eclipse.persistence.internal.oxm.record.AbstractMarshalRecord<org.eclipse.persistence.internal.core.sessions.CoreAbstractSession,org.eclipse.persistence.internal.core.helper.CoreField,org.eclipse.persistence.internal.oxm.XMLMarshaller,org.eclipse.persistence.internal.oxm.NamespaceResolver>, org.eclipse.persistence.internal.oxm.record.MarshalRecord<org.eclipse.persistence.internal.core.sessions.CoreAbstractSession,org.eclipse.persistence.internal.core.helper.CoreField,org.eclipse.persistence.internal.oxm.XMLMarshaller,org.eclipse.persistence.internal.oxm.NamespaceResolver>, org.eclipse.persistence.internal.oxm.record.XMLRecord<org.eclipse.persistence.internal.core.sessions.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:
  • Constructor Details

    • JSONFormattedWriterRecord

      public JSONFormattedWriterRecord()
    • JSONFormattedWriterRecord

      public JSONFormattedWriterRecord(OutputStream outputStream)
    • JSONFormattedWriterRecord

      public JSONFormattedWriterRecord(OutputStream outputStream, String callbackName)
    • JSONFormattedWriterRecord

      public JSONFormattedWriterRecord(Writer writer)
    • JSONFormattedWriterRecord

      public JSONFormattedWriterRecord(Writer writer, String callbackName)
  • Method Details

    • startDocument

      public void startDocument(String encoding, String version)
      Description copied from class: JSONWriterRecord
      INTERNAL:
      Overrides:
      startDocument in class JSONWriterRecord
      Parameters:
      encoding - The XML document will be encoded using this encoding.
      version - This specifies the version of XML.
    • endDocument

      public void endDocument()
      INTERNAL:
      Overrides:
      endDocument in class JSONWriterRecord
    • closeComplex

      protected void closeComplex() throws IOException
      Overrides:
      closeComplex in class JSONWriterRecord
      Throws:
      IOException
    • openStartElement

      public void openStartElement(org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment, org.eclipse.persistence.internal.oxm.NamespaceResolver namespaceResolver)
      INTERNAL:
      Specified by:
      openStartElement in interface org.eclipse.persistence.internal.oxm.record.MarshalRecord<org.eclipse.persistence.internal.core.sessions.CoreAbstractSession,org.eclipse.persistence.internal.core.helper.CoreField,org.eclipse.persistence.internal.oxm.XMLMarshaller,org.eclipse.persistence.internal.oxm.NamespaceResolver>
      Overrides:
      openStartElement in class JSONWriterRecord
      Parameters:
      xPathFragment - The XPathFragment contains the name and prefix information about the XML element being ended.
      namespaceResolver - The NamespaceResolver can be used to resolve the namespace URI for the namespace prefix held by the XPathFragment (if required).
    • element

      public void element(org.eclipse.persistence.internal.oxm.XPathFragment frag)
      INTERNAL:
      Overrides:
      element in class JSONWriterRecord
      Parameters:
      frag - The XPathFragment of the element
    • writeListSeparator

      protected void writeListSeparator() throws IOException
      Overrides:
      writeListSeparator in class JSONWriterRecord
      Throws:
      IOException
    • writeSeparator

      protected void writeSeparator() throws IOException
      Overrides:
      writeSeparator in class JSONWriterRecord
      Throws:
      IOException
    • endElement

      public void endElement(org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment, org.eclipse.persistence.internal.oxm.NamespaceResolver namespaceResolver)
      INTERNAL:
      Specified by:
      endElement in interface org.eclipse.persistence.internal.oxm.record.MarshalRecord<org.eclipse.persistence.internal.core.sessions.CoreAbstractSession,org.eclipse.persistence.internal.core.helper.CoreField,org.eclipse.persistence.internal.oxm.XMLMarshaller,org.eclipse.persistence.internal.oxm.NamespaceResolver>
      Overrides:
      endElement in class JSONWriterRecord
      Parameters:
      xPathFragment - The XPathFragment contains the name and prefix information about the XML element being ended.
      namespaceResolver - The NamespaceResolver can be used to resolve the namespace URI for the namespace prefix held by the XPathFragment (if required).
    • startCollection

      public void startCollection()
      Description copied from class: MarshalRecord
      This method is used to inform the MarshalRecord that the element events it is about to receive are part of a collection.
      Specified by:
      startCollection in interface org.eclipse.persistence.internal.oxm.record.MarshalRecord<org.eclipse.persistence.internal.core.sessions.CoreAbstractSession,org.eclipse.persistence.internal.core.helper.CoreField,org.eclipse.persistence.internal.oxm.XMLMarshaller,org.eclipse.persistence.internal.oxm.NamespaceResolver>
      Overrides:
      startCollection in class JSONWriterRecord
      See Also:
    • endEmptyCollection

      protected void endEmptyCollection()
      Overrides:
      endEmptyCollection in class JSONWriterRecord
    • endCollection

      public void endCollection()
      Description copied from class: MarshalRecord
      This method is used to inform the MarshalRecord that it is done receiving element events that are part of a collection.
      Specified by:
      endCollection in interface org.eclipse.persistence.internal.oxm.record.MarshalRecord<org.eclipse.persistence.internal.core.sessions.CoreAbstractSession,org.eclipse.persistence.internal.core.helper.CoreField,org.eclipse.persistence.internal.oxm.XMLMarshaller,org.eclipse.persistence.internal.oxm.NamespaceResolver>
      Overrides:
      endCollection in class JSONWriterRecord
      See Also:
    • characters

      public void characters(String value)
      INTERNAL:
      Specified by:
      characters in interface org.eclipse.persistence.internal.oxm.record.MarshalRecord<org.eclipse.persistence.internal.core.sessions.CoreAbstractSession,org.eclipse.persistence.internal.core.helper.CoreField,org.eclipse.persistence.internal.oxm.XMLMarshaller,org.eclipse.persistence.internal.oxm.NamespaceResolver>
      Overrides:
      characters in class JSONWriterRecord
      Parameters:
      value - This is the entire value of the text node.
    • node

      public void node(Node node, org.eclipse.persistence.internal.oxm.NamespaceResolver namespaceResolver)
      Receive notification of a node.
      Specified by:
      node in interface org.eclipse.persistence.internal.oxm.record.MarshalRecord<org.eclipse.persistence.internal.core.sessions.CoreAbstractSession,org.eclipse.persistence.internal.core.helper.CoreField,org.eclipse.persistence.internal.oxm.XMLMarshaller,org.eclipse.persistence.internal.oxm.NamespaceResolver>
      Overrides:
      node in class MarshalRecord<org.eclipse.persistence.internal.oxm.XMLMarshaller>
      Parameters:
      node - The Node to be added to the document
      namespaceResolver - The NamespaceResolver can be used to resolve the namespace URI/prefix of the node
    • writeKey

      protected void writeKey(org.eclipse.persistence.internal.oxm.XPathFragment xPathFragment) throws IOException
      Overrides:
      writeKey in class JSONWriterRecord
      Throws:
      IOException