Skip to main content

Notice: This Wiki is now read only and edits are no longer 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"

(Namespaces)
(Bug 350483:Object to JSON Support)
Line 7: Line 7:
 
*XmlAnyAttribute  
 
*XmlAnyAttribute  
 
*XmlAnyElement
 
*XmlAnyElement
*XmlAttribute
+
*XmlAttribute
 
*XmlAttributeRef  
 
*XmlAttributeRef  
 
*XmlElement  
 
*XmlElement  
Line 57: Line 57:
 
*XmlWriteTransformer
 
*XmlWriteTransformer
 
*XmlWriteTransformers
 
*XmlWriteTransformers
 
  
 
=='''Inheritance'''==
 
=='''Inheritance'''==

Revision as of 15:50, 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.JSON_NAMESPACES, namespaces);

If the namespace map is set on the marshaller it will be used to prefix elements during the marshal operation.

 jsonMarshaller.setProperty(JAXBContext.JSON_USE_NAMESPACES, true);

The namespaces will be give the prefix from the map separated with a `.` ie:

 {"ns0.employee:{
     "ns0.id":123
    }
 }

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.

Attributes

JSON doesn't have the concept as attributes so by default when marshaling anything mapped as an attribute will be marshalled as an element. During unmarshal elements will trigger both the attribute and element events to allow either the mapped attribute or element to handle the value. If there is an element and attribute with the same name this will cause problems. Additionally there would likely be issues if an AnyAttribute or Any existed as all items would probably be duplicated in the AnyAttribute mapping and the Any Mapping.

Users will be able to override the default behaviors by providing a prefix to marshal with attributes and to recognize during unmarshal. In the example below the number attribute is mapped as an attribute.

 jsonUnmarshaller.setProperty(JAXBContext.JSON_ATTRIBUTE_PREFIX, "@");
 jsonMarshaller.setProperty(JAXBContext.JSON_ATTRIBUTE_PREFIX, "@") ;
{"phone":{
  "area-code":"613",
  "@number":"1234567"
  }
}

Back to the top