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

EclipseLink/DesignDocs/459464

< EclipseLink‎ | DesignDocs
Revision as of 16:31, 9 February 2015 by Unnamed Poltroon (Talk) (initial summary)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Redesign of type property in JSON processing

Bug 459464

Document History

Date Author Version Description & Notes
February 9th 2015 Martin Vojtek Initial revision

Overview

Special handling of JSON type property is deprecated. If there is need to identify type of JSON object - due to missing root element or some special inheritance requirements, it is necessary to specify fully qualified type property with http://www.w3.org/2001/XMLSchema-instance namespace.

Namespace prefix needs to be specified as JAXBContext property in JAXB Context or Marshaller or Unmarshaller:

unmarshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);

       Map<String, String> namespaces = new HashMap<>();
       namespaces.put(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi");
       unmarshaller.setProperty(JAXBContextProperties.NAMESPACE_PREFIX_MAPPER, namespaces);

Json in MOXy 2.5.x:

{

 "person": {
   "type": "developer",
   "name": "Martin Vojtek"
 }

}

Json in MOXy 2.6.0:

{

 "person": {
   "xsi.type": "developer",
   "name": "Martin Vojtek"
 }

}

There is also change in default handling of simple xsd types when using namespaces. To specify simple xsd type as type value, there is no need to specify xsd prefix. Example:

Json in MOXy 2.5.x:

{

 "foo": {
   "field": {
     "xsi.type": "xsd.int",
     "value": 10
   }
 }

}

Json in MOXy 2.6.0:

{

 "foo": {
   "field": {
     "xsi.type": "int",
     "value": 10
   }
 }

}

To provide backward compatibility options, new system properties and JAXBContext/Marshaller/Unmarshaller properties are introduced:

org.eclipse.persistence.json.type-compatibility org.eclipse.persistence.json.use-xsd-types-prefix

Back to the top