Class JSONWriterRecord
- All Implemented Interfaces:
AbstractMarshalRecord<CoreAbstractSession,
,CoreField, XMLMarshaller, NamespaceResolver> MarshalRecord<CoreAbstractSession,
,CoreField, XMLMarshaller, NamespaceResolver> XMLRecord<CoreAbstractSession>
- Direct Known Subclasses:
JSONFormattedWriterRecord
Use this type of MarshalRecord when the marshal target is a Writer and the JSON should not be formatted with carriage returns or indenting.
XMLContext xmlContext = new XMLContext("session-name");
XMLMarshaller xmlMarshaller = xmlContext.createMarshaller();
JSONRecord jsonWriterRecord = new JSONWriterRecord();
jsonWriterRecord.setWriter(myWriter);
xmlMarshaller.marshal(myObject, jsonWriterRecord);
If the marshal(Writer) and setMediaType(MediaType.APPLICATION_JSON) and setFormattedOutput(false) method is called on XMLMarshaller, then the Writer is automatically wrapped in a JSONWriterRecord.
XMLContext xmlContext = new XMLContext("session-name");
XMLMarshaller xmlMarshaller = xmlContext.createMarshaller();
xmlMarshaller.setMediaType(MediaType.APPLICATION_JSON);
xmlMarshaller xmlMarshaller.setFormattedOutput(false);
xmlMarshaller.marshal(myObject, myWriter);
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
This class will typically be used in conjunction with an XMLFragmentReader.protected static class
Instances of this class are used to maintain state about the current level of the JSON message being marshalled.protected static interface
protected static class
Nested classes/interfaces inherited from interface org.eclipse.persistence.internal.oxm.record.MarshalRecord
MarshalRecord.CycleDetectionStack<E>
Nested classes/interfaces inherited from interface org.eclipse.persistence.internal.oxm.record.XMLRecord
XMLRecord.Nil
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
protected String
protected CharacterEscapeHandler
protected boolean
protected CharsetEncoder
protected boolean
protected JSONWriterRecord.Level
protected static final String
protected JSONWriterRecord.Output
Fields inherited from class org.eclipse.persistence.oxm.record.MarshalRecord
COLON_W_SCHEMA_NIL_ATTRIBUTE, textWrapperFragment, TRUE
Fields inherited from class org.eclipse.persistence.internal.oxm.record.AbstractMarshalRecordImpl
equalNamespaceResolvers, hasCustomNamespaceMapper, marshaller, namespaceAware, namespaceResolver, session
Fields inherited from interface org.eclipse.persistence.internal.oxm.record.XMLRecord
DEFAULT_ATTRIBUTE_GROUP, NIL
-
Constructor Summary
ConstructorDescriptionJSONWriterRecord
(OutputStream outputStream) JSONWriterRecord
(OutputStream outputStream, String callbackName) JSONWriterRecord
(Writer writer) JSONWriterRecord
(Writer writer, String callbackName) -
Method Summary
Modifier and TypeMethodDescriptionvoid
INTERNAL:void
attribute
(XPathFragment xPathFragment, NamespaceResolver namespaceResolver, Object value, QName schemaType) Convert the value if necessary and write out the attribute and converted value.void
attribute
(XPathFragment xPathFragment, NamespaceResolver namespaceResolver, String value) INTERNAL:void
INTERNAL:void
characters
(String value) INTERNAL:void
characters
(String value, boolean isString, boolean isAttribute) INTERNAL:void
characters
(QName schemaType, Object value, String mimeType, boolean isCDATA) Convert the value if necessary and write out the converted value.void
characters
(QName schemaType, Object value, String mimeType, boolean isCDATA, boolean isAttribute) protected void
void
INTERNAL:void
defaultNamespaceDeclaration
(String defaultNamespace) Add the defaultNamespace declarationvoid
element
(XPathFragment frag) INTERNAL:void
emptyAttribute
(XPathFragment xPathFragment, NamespaceResolver namespaceResolver) Used when an nil attribute should be writtenboolean
emptyCollection
(XPathFragment xPathFragment, NamespaceResolver namespaceResolver, boolean openGrouping) Handle marshal of an empty collection.void
emptyComplex
(XPathFragment xPathFragment, NamespaceResolver namespaceResolver) Used when an empty complex item should be writtenvoid
emptySimple
(NamespaceResolver namespaceResolver) Used when an empty simple value should be writtenprotected void
void
This method is used to inform the MarshalRecord that it is done receiving element events that are part of a collection.void
INTERNAL:void
endElement
(XPathFragment xPathFragment, NamespaceResolver namespaceResolver) INTERNAL:protected void
void
endPrefixMappings
(NamespaceResolver namespaceResolver) INTERNAL: override so we don't iterate over namespaces when endPrefixMapping doesn't do anythingvoid
flush()
void
char
INTERNAL: The character used to separate the prefix and uri portions when namespaces are presentprotected String
getStringForQName
(QName qName) INTERNAL: The optional fragment used to wrap the text() mappingsReturn the Writer that the object will be marshalled to.boolean
void
marshalWithoutRootElement
(ObjectBuilder treeObjectBuilder, Object object, Descriptor descriptor, Root root, boolean isXMLRoot) INTERNAL:void
namespaceDeclaration
(String prefix, String namespaceURI) Add the specified namespace declarationvoid
namespaceDeclarations
(NamespaceResolver namespaceResolver) INTERNAL:void
nilComplex
(XPathFragment xPathFragment, NamespaceResolver namespaceResolver) INTERNAL:void
nilSimple
(NamespaceResolver namespaceResolver) INTERNAL:void
node
(Node node, NamespaceResolver namespaceResolver, String uri, String name) Receive notification of a node.void
openStartElement
(XPathFragment xPathFragment, NamespaceResolver namespaceResolver) INTERNAL:void
setCallbackName
(String callbackName) void
setMarshaller
(XMLMarshaller marshaller) INTERNAL:void
Set the Writer that the object will be marshalled to.protected void
INTERNAL:void
This method is used to inform the MarshalRecord that the element events it is about to receive are part of a collection.void
startDocument
(String encoding, String version) INTERNAL:void
startPrefixMappings
(NamespaceResolver namespaceResolver) INTERNAL: override so we don't iterate over namespaces when startPrefixMapping doesn't do anythingprotected void
writeKey
(XPathFragment xPathFragment) protected void
protected void
protected void
writeValue
(String value, boolean isAttribute) INTERNAL:Methods inherited from class org.eclipse.persistence.oxm.record.MarshalRecord
add, addGroupingElement, addPositionalNodes, afterContainmentMarshal, beforeContainmentMarshal, clear, closeStartGroupingElements, endPrefixMapping, getCurrentAttributeGroup, getCycleDetectionStack, getDocument, getDOM, getGroupingElements, getLocalName, getNameForFragment, getNamespaceURI, getPositionalNodes, getPrefixBytes, getPrefixForFragment, getValueToWrite, node, openStartGroupingElements, popAttributeGroup, predicateAttribute, processNamespaceResolverForXSIPrefix, pushAttributeGroup, put, removeGroupingElement, setGroupingElement, setSession, startPrefixMapping, transformToXML, writeHeader
Methods inherited from class org.eclipse.persistence.internal.oxm.record.AbstractMarshalRecordImpl
addExtraNamespacesToNamespaceResolver, addXsiTypeAndClassIndicatorIfRequired, addXsiTypeAndClassIndicatorIfRequired, attributeWithoutQName, getConversionManager, getLeafElementType, getMarshaller, getNamespaceResolver, getOwningObject, getSession, hasCustomNamespaceMapper, hasEqualNamespaceResolvers, isNamespaceAware, isXOPPackage, removeExtraNamespacesFromNamespaceResolver, resolveNamespacePrefix, setCustomNamespaceMapper, setEqualNamespaceResolvers, setLeafElementType, setLeafElementType, setNamespaceResolver, setOwningObject, setXOPPackage, writeXsiTypeAttribute, writeXsiTypeAttribute
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.persistence.internal.oxm.record.AbstractMarshalRecord
addExtraNamespacesToNamespaceResolver, addXsiTypeAndClassIndicatorIfRequired, addXsiTypeAndClassIndicatorIfRequired, getLeafElementType, getMarshaller, getNamespaceResolver, getOwningObject, hasEqualNamespaceResolvers, isNamespaceAware, resolveNamespacePrefix, setCustomNamespaceMapper, setEqualNamespaceResolvers, setLeafElementType, setNamespaceResolver, setOwningObject, setXOPPackage, writeXsiTypeAttribute, writeXsiTypeAttribute
Methods inherited from interface org.eclipse.persistence.internal.oxm.record.MarshalRecord
attributeWithoutQName, hasCustomNamespaceMapper, isXOPPackage, removeExtraNamespacesFromNamespaceResolver, setLeafElementType
Methods inherited from interface org.eclipse.persistence.internal.oxm.record.XMLRecord
getConversionManager, getSession
-
Field Details
-
isProcessingCData
protected boolean isProcessingCData -
NULL
- See Also:
-
attributePrefix
-
charactersAllowed
protected boolean charactersAllowed -
encoder
-
characterEscapeHandler
-
callbackName
-
writer
-
level
-
-
Constructor Details
-
JSONWriterRecord
public JSONWriterRecord() -
JSONWriterRecord
-
JSONWriterRecord
-
JSONWriterRecord
-
JSONWriterRecord
-
-
Method Details
-
setCallbackName
-
setMarshaller
INTERNAL:- Specified by:
setMarshaller
in interfaceAbstractMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Specified by:
setMarshaller
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
setMarshaller
in classAbstractMarshalRecordImpl<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver>
-
emptyCollection
public boolean emptyCollection(XPathFragment xPathFragment, NamespaceResolver namespaceResolver, boolean openGrouping) Handle marshal of an empty collection.- Specified by:
emptyCollection
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
emptyCollection
in classMarshalRecord<XMLMarshaller>
- Parameters:
openGrouping
- if grouping elements should be marshalled for empty collections
-
forceValueWrapper
public void forceValueWrapper()- Specified by:
forceValueWrapper
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
forceValueWrapper
in classMarshalRecord<XMLMarshaller>
-
getWriter
Return the Writer that the object will be marshalled to.- Returns:
- The marshal target.
-
setWriter
Set the Writer that the object will be marshalled to.- Parameters:
writer
- The marshal target.
-
namespaceDeclaration
Description copied from class:MarshalRecord
Add the specified namespace declaration- Specified by:
namespaceDeclaration
in interfaceAbstractMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Specified by:
namespaceDeclaration
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
namespaceDeclaration
in classMarshalRecord<XMLMarshaller>
-
defaultNamespaceDeclaration
Description copied from class:MarshalRecord
Add the defaultNamespace declaration- Overrides:
defaultNamespaceDeclaration
in classMarshalRecord<XMLMarshaller>
-
startDocument
INTERNAL:- Specified by:
startDocument
in classMarshalRecord<XMLMarshaller>
- Parameters:
encoding
- The XML document will be encoded using this encoding.version
- This specifies the version of XML.
-
writeListSeparator
- Throws:
IOException
-
writeSeparator
- Throws:
IOException
-
startCallback
INTERNAL:- Throws:
IOException
-
endDocument
public void endDocument()INTERNAL:- Specified by:
endDocument
in classMarshalRecord<XMLMarshaller>
-
openStartElement
INTERNAL:- Specified by:
openStartElement
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
openStartElement
in classMarshalRecord<XMLMarshaller>
- 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
INTERNAL:- Specified by:
element
in classMarshalRecord<XMLMarshaller>
- Parameters:
frag
- The XPathFragment of the element
-
attribute
INTERNAL:- Specified by:
attribute
in interfaceAbstractMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Specified by:
attribute
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Specified by:
attribute
in classMarshalRecord<XMLMarshaller>
- Parameters:
namespaceURI
- The namespace URI, if the attribute is not namespace qualified the value of this parameter wil be null.localName
- The local name of the attribute.qName
- The qualified name of the attribute.value
- This is the complete value for the attribute.
-
attribute
public void attribute(XPathFragment xPathFragment, NamespaceResolver namespaceResolver, String value) INTERNAL:- Specified by:
attribute
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Specified by:
attribute
in classMarshalRecord<XMLMarshaller>
- 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).value
- This is the complete value for the attribute.
-
startPrefixMappings
INTERNAL: override so we don't iterate over namespaces when startPrefixMapping doesn't do anything- Overrides:
startPrefixMappings
in classMarshalRecord<XMLMarshaller>
-
endPrefixMappings
INTERNAL: override so we don't iterate over namespaces when endPrefixMapping doesn't do anything- Overrides:
endPrefixMappings
in classMarshalRecord<XMLMarshaller>
-
closeStartElement
public void closeStartElement()INTERNAL:- Specified by:
closeStartElement
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Specified by:
closeStartElement
in classMarshalRecord<XMLMarshaller>
-
endElement
INTERNAL:- Specified by:
endElement
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Specified by:
endElement
in classMarshalRecord<XMLMarshaller>
- 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).
-
closeComplex
- Throws:
IOException
-
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 interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
startCollection
in classMarshalRecord<XMLMarshaller>
- See Also:
-
endEmptyCollection
protected void endEmptyCollection() -
endCallback
- Throws:
IOException
-
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 interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
endCollection
in classMarshalRecord<XMLMarshaller>
- See Also:
-
characters
INTERNAL:- Specified by:
characters
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Specified by:
characters
in classMarshalRecord<XMLMarshaller>
- Parameters:
value
- This is the entire value of the text node.
-
characters
INTERNAL: -
attribute
public void attribute(XPathFragment xPathFragment, NamespaceResolver namespaceResolver, Object value, QName schemaType) Description copied from class:MarshalRecord
Convert the value if necessary and write out the attribute and converted value.- Specified by:
attribute
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
attribute
in classMarshalRecord<XMLMarshaller>
-
characters
Description copied from class:MarshalRecord
Convert the value if necessary and write out the converted value.- Specified by:
characters
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
characters
in classMarshalRecord<XMLMarshaller>
-
characters
-
namespaceDeclarations
INTERNAL:- Overrides:
namespaceDeclarations
in classMarshalRecord<XMLMarshaller>
- Parameters:
namespaceResolver
- The NamespaceResolver contains the namespace prefix and URI pairings that need to be declared.
-
nilComplex
INTERNAL:- Specified by:
nilComplex
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
nilComplex
in classMarshalRecord<XMLMarshaller>
-
nilSimple
INTERNAL:- Specified by:
nilSimple
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
nilSimple
in classMarshalRecord<XMLMarshaller>
-
emptySimple
Used when an empty simple value should be written- Specified by:
emptySimple
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
emptySimple
in classMarshalRecord<XMLMarshaller>
- Since:
- EclipseLink 2.4
-
emptyAttribute
Description copied from class:MarshalRecord
Used when an nil attribute should be written- Specified by:
emptyAttribute
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
emptyAttribute
in classMarshalRecord<XMLMarshaller>
-
emptyComplex
Used when an empty complex item should be written- Specified by:
emptyComplex
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
emptyComplex
in classMarshalRecord<XMLMarshaller>
- Since:
- EclipseLink 2.4
-
marshalWithoutRootElement
public void marshalWithoutRootElement(ObjectBuilder treeObjectBuilder, Object object, Descriptor descriptor, Root root, boolean isXMLRoot) INTERNAL:- Overrides:
marshalWithoutRootElement
in classMarshalRecord<XMLMarshaller>
-
cdata
INTERNAL:- Specified by:
cdata
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Specified by:
cdata
in classMarshalRecord<XMLMarshaller>
- Parameters:
value
- This is the value of the text to be wrapped
-
getNamespaceSeparator
public char getNamespaceSeparator()INTERNAL: The character used to separate the prefix and uri portions when namespaces are present- Specified by:
getNamespaceSeparator
in interfaceXMLRecord<CoreAbstractSession>
- Overrides:
getNamespaceSeparator
in classAbstractMarshalRecordImpl<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Since:
- 2.4
-
getTextWrapperFragment
INTERNAL: The optional fragment used to wrap the text() mappings- Specified by:
getTextWrapperFragment
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
getTextWrapperFragment
in classMarshalRecord<XMLMarshaller>
- Since:
- 2.4
-
writeKey
- Throws:
IOException
-
writeValue
INTERNAL: -
getStringForQName
- Overrides:
getStringForQName
in classMarshalRecord<XMLMarshaller>
-
node
Receive notification of a node.- Specified by:
node
in classMarshalRecord<XMLMarshaller>
- Parameters:
node
- The Node to be added to the documentnamespaceResolver
- The NamespaceResolver can be used to resolve the namespace URI/prefix of the nodeuri
- replacement root name for the nodename
- replacement root namespace for the node namespace URI/prefix of the node
-
isWrapperAsCollectionName
public boolean isWrapperAsCollectionName()- Specified by:
isWrapperAsCollectionName
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
isWrapperAsCollectionName
in classMarshalRecord<XMLMarshaller>
-
flush
public void flush()- Specified by:
flush
in interfaceMarshalRecord<CoreAbstractSession,
CoreField, XMLMarshaller, NamespaceResolver> - Overrides:
flush
in classMarshalRecord<XMLMarshaller>
-