This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 459464 - Enhancement Request: Redesign of type property in JSON processing
Summary: Enhancement Request: Redesign of type property in JSON processing
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Martin Vojtek CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 447393
Blocks:
  Show dependency tree
 
Reported: 2015-02-09 09:24 EST by Martin Vojtek CLA
Modified: 2022-06-09 10:09 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Vojtek CLA 2015-02-09 09:24:00 EST
Special handling of JSON type property should be deprecated. If there is need to identify type of JSON object - due to missing root element or some special inheritance requirements, it should be 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 should also be change in default handling of simple xsd types when using namespaces. To specify simle xsd type as type value, there should be 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 should be introduced:

org.eclipse.persistence.json.type-compatibility
org.eclipse.persistence.json.use-xsd-types-prefix
Comment 1 Martin Vojtek CLA 2015-02-09 15:57:24 EST
Design doc created https://wiki.eclipse.org/EclipseLink/DesignDocs/459464
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:09:53 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink