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"

(Bug 350483:Object to JSON Support)
(Bug 350483:Object to JSON Support)
Line 58: Line 58:
 
*XmlWriteTransformers
 
*XmlWriteTransformers
  
'''Other Concepts'''
+
=='''Other Concepts'''==
 
*Inheritance- XML - <prefix:vehicle xsi:type="prefix:car-type">
 
*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",
 
JSON-Can unmarshal "type":"prefix:car-type" or "type":"car-type", Should it marshal "type":"prefix:car-type" or "type":"car-type",
  
 
*Namespaces
 
*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.
 +
<source lang="java">
 +
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);
 +
</source>
 +
 
*Date types
 
*Date types
 
*xsi:type attribute
 
*xsi:type attribute
Line 70: Line 82:
 
       <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>
 
       <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>
  
*JSON supports no "root element"
+
*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.

Revision as of 14:44, 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

Other Concepts

  • 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
  • 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.

Back to the top