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/459464"

(initial summary)
 
m (Overview)
Line 21: Line 21:
 
Namespace prefix needs to be specified as JAXBContext property in JAXB Context or Marshaller or Unmarshaller:
 
Namespace prefix needs to be specified as JAXBContext property in JAXB Context or Marshaller or Unmarshaller:
  
unmarshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
+
  unmarshaller.setProperty(JAXBContextProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
        Map<String, String> namespaces = new HashMap<>();
+
  Map<String, String> namespaces = new HashMap<>();
        namespaces.put(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi");
+
  namespaces.put(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi");
        unmarshaller.setProperty(JAXBContextProperties.NAMESPACE_PREFIX_MAPPER, namespaces);
+
  unmarshaller.setProperty(JAXBContextProperties.NAMESPACE_PREFIX_MAPPER, namespaces);
  
 
Json in MOXy 2.5.x:
 
Json in MOXy 2.5.x:
  
{
+
  {
  "person": {
+
    "person": {
    "type": "developer",
+
      "type": "developer",
    "name": "Martin Vojtek"
+
      "name": "Martin Vojtek"
 +
    }
 
   }
 
   }
}
 
  
 
Json in MOXy 2.6.0:
 
Json in MOXy 2.6.0:
  
{
+
  {
  "person": {
+
    "person": {
    "xsi.type": "developer",
+
      "xsi.type": "developer",
    "name": "Martin Vojtek"
+
      "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:
 
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:
Line 48: Line 48:
 
Json in MOXy 2.5.x:
 
Json in MOXy 2.5.x:
  
{
+
  {
  "foo": {
+
    "foo": {
    "field": {
+
      "field": {
      "xsi.type": "xsd.int",
+
        "xsi.type": "xsd.int",
      "value": 10
+
        "value": 10
 +
      }
 
     }
 
     }
 
   }
 
   }
}
 
  
 
Json in MOXy 2.6.0:
 
Json in MOXy 2.6.0:
  
{
+
  {
  "foo": {
+
    "foo": {
    "field": {
+
      "field": {
      "xsi.type": "int",
+
        "xsi.type": "int",
      "value": 10
+
        "value": 10
 +
      }
 
     }
 
     }
   }
+
   }   
}   
+
  
 
To provide backward compatibility options, new system properties and JAXBContext/Marshaller/Unmarshaller properties are introduced:
 
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.type-compatibility
 +
 
org.eclipse.persistence.json.use-xsd-types-prefix
 
org.eclipse.persistence.json.use-xsd-types-prefix

Revision as of 16:36, 9 February 2015

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