Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/DesignDocs/350483"

(no "root element" support)
(no "root element" support)
Line 91: Line 91:
 
</source>
 
</source>
 
During marshal if there is no @XmlRootElement specified then the JSON document won't have a root element (as above).
 
During marshal if there is no @XmlRootElement specified then the JSON document won't have a root element (as above).
During an unmarshal operation if the document has more than one child element it will be treated as an object without a root element.
+
During an unmarshal operation if the document has more than one child element it will be treated as an object without a root element. The only unmarshal methods that will be supported for the non root element case will be those that take a Class argument that specifies the class to unmarshal to.

Revision as of 15:18, 2 August 2011

Bug 350483:Object to JSON Support

JAXB Annotations

  • XmlAccessOrder
  • XmlAccessorOrder
  • XmlAccessorType
  • XmlAccessType
  • XmlAnyAttribute
  • XmlAnyElement
  • XmlAttribute
  • XmlAttributeRef
  • XmlElement
  • XmlElementWrapper
  • XmlID
  • XmlIDREF
  • XmlJavaTypeAdapter
  • XmlJavaTypeAdapters
  • XmlList
  • XmlMimeType
  • XmlMixed
  • XmlNs
  • XmlNsForm
  • XmlRootElement
  • XmlSchema
  • XmlSeeAlso
  • XmlTransient
  • XmlType
  • XmlValue

MOXy Annotations

  • XmlAccessMethods
  • XmlCDATA
  • XmlClassExtractor
  • XmlContainerPolicy
  • XmlCustomizer
  • XMLDiscriminatorNode
  • XMLDiscriminatorValue
  • XmlElementsJoinNodes
  • XmlInverseReference
  • XmlIsSetNullPolicy
  • XmlJoinNode
  • XmlJoinNodes
  • XmlKey
  • XmlMashalNullRepresentation
  • XmlNameTransformer
  • XmlNullPolicy
  • XmlParameter
  • XmlPath
  • XmlPaths
  • XmlProperties
  • XmlProperty
  • XmlReadOnly
  • XmlReadTransformer
  • XmlTransformation
  • XmlVirtualAccessMethods
  • XmlVirtualAccessMethodsSchema
  • XmlWriteOnly
  • XmlWriteTransformer
  • XmlWriteTransformers


Inheritance

XML - <prefix:vehicle xsi:type="prefix:car-type"> JSON-Can unmarshal "type":"prefix:car-type" or "type":"car-type", Should it marshal "type":"prefix:car-type" or "type":"car-type",

Namespaces

By default namespaces/prefixes will be ignored during marshal and unmarshal operations. This default behavior is a problem if there are multiple mappings with the same local name in different namespaces as there would be no way to distinguish between those mappings. Users will be able to provide a Map of namespaces to customize the behavior.

 Map namespaces = new HashMap<String, String>();
 namespaces.put("ns1", "namespace1");
 namespaces.put("ns2", "namespace2");
 jsonUnmarshaller.setProperty(JAXBContext.NAMESPACES, namespaces);
 jsonMarshaller.setProperty(JAXBContext.NAMESPACE_PREFIX, JAXBCONTEXT.USE);
// jsonMarshaller.setProperty(JAXBContext.NAMESPACE_SEPERATOR, JAXBCONTEXT.USE);

Date Types

XSI type attribute

ie:CompositeObjectMapping to Object.class attributes of type java.lang.Object (or Collection of Objects).

    • Equivalent XML -
  <responsibilities>
     <responsibility xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xsi:type="xsd:string">Fix Bugs</responsibility>

no "root element" support

JSON supports documents with no root element

{"area-code":"613",
 "number":"1234567"}

During marshal if there is no @XmlRootElement specified then the JSON document won't have a root element (as above). During an unmarshal operation if the document has more than one child element it will be treated as an object without a root element. The only unmarshal methods that will be supported for the non root element case will be those that take a Class argument that specifies the class to unmarshal to.

Back to the top