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.
Difference between revisions of "EclipseLink/Release/2.4.0/JSONBinding"
Line 90: | Line 90: | ||
− | {| border="0" cellpadding="5" style="background:#f9f9f9; border:1px dashed 2f6fab" | + | {| border="0" cellpadding="5" style="background:#f9f9f9; border:1px dashed #2f6fab" |
|- | |- | ||
|XmlAttributeRef | |XmlAttributeRef |
Revision as of 13:33, 14 June 2012
Contents
Object-to-JSON Binding Layer
Overview
New in EclipseLink 2.4 is support for converting objects to and from JSON. This can be useful when creating RESTful services, as JAX-RS services often accept both XML (application/xml) and JSON (application/json) messages.
Same Flexibility as Object-to-XML Mapping
JSON binding is compatible with most existing MOXy extensions. This includes:
- External bindings file
- Dynamic JAXB
- Extensible models
XML and JSON Messages with One Set of Mappings
Both an XML message such as:
<foo xmlns="urn:examle" id="123"> <bar>Hello World</bar> </foo>
and a JSON message such as:
{"foo" : { "id" : 123, "bar : "Hello World" }}
can be supported by a single object model:
@XmlRootElement(namespace="urn:example") public class Foo { @XmlAttribute private int id; @XmlElement(namespace="urn:example") private String bar; }
No Additional Compile-Time Dependencies
JSON binding does not require any additional compile-time dependencies above and beyond what is required for normal JAXB usage.
Easy to Use with JAX-RS
EclipseLink JSON support makes it easy to implement MessageBodyReader and MessageBodyWriter classes for use with RESTful web services.
Marshalling and Unmarshalling with JSON
Adapting your application to produce and consume JSON is as easy as setting a property on your JAXB Marshaller or Unmarshaller:
import org.eclipse.persistence.jaxb.MarshallerProperties; import org.eclipse.persistence.oxm.MediaType; ... Marshaller m = jaxbContext.createMarshaller(); m.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); Unmarshaller u = jaxbContext.createUnmarshaller(); u.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); ...
Unsupported MOXy/JAXB Annotations
The following annotations are not applicable to JSON:
XmlAttributeRef | XmlMimeType | XmlMixed | XmlNs |
XmlNsForm | XmlSchema | XmlProperties | XmlProperty |
XmlVirtualAccessMethods | XmlVirtualAccessMethodsSchema | XmlIsSetNullPolicy | XmlJoinNodes |
XmlMarshalNullRepresentation | XmlNullPolicy | XmlParameter | XmlPath |
XmlPaths | XmlCDATA |