Skip to main content
Jump to: navigation, search

EclipseLink/Examples/MOXy/JSON Metadata

< EclipseLink‎ | Examples‎ | MOXy
Revision as of 13:27, 18 June 2012 by (Talk | contribs) (New page: <div style="margin:5px;float:right;border:1px solid #000000;padding:5px">__TOC__</div> =Representing MOXy Metadata in JSON= MOXy's support for JSON brings with it the ability to write M...)

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

Representing MOXy Metadata in JSON

MOXy's support for JSON brings with it the ability to write MOXy External Bindings files in JSON. An external metadata representation is useful when:

  • You cannot modify the domain model (it may come from a third party)
  • You do not want to introduce compile dependencies on JAXB APIs (if you are using a version of Java prior to Java SE 6)
  • You want to apply multiple JAXB mappings to a domain model (you are limited to one representation with annotations)
  • Your object model already contains so many annotations from other technologies that adding more would make the class unreadable

Bindings File

The bindings file contains the same information as the JAXB annotations. Like with annotations you only need to specify metadata to override default behavior. The JSON bindings file can be used in place of, or in combination with, an XML bindings file. Below is an example JSON bindings file, as well as its XML equivalent:


   "package-name" : "org.example.bindingsfile",
   "xml-schema" : {
      "element-form-default" : "QUALIFIED",
      "namespace" : ""
   "java-types" : {
      "java-type" : [ {
         "name" : "Customer",
         "xml-type" : {
            "prop-order" : "firstName lastName address phoneNumbers"
         "xml-root-element" : {},
         "java-attributes" : {
            "xml-element" : [ 
                {"java-attribute" : "firstName","name" : "first-name"}, 
                {"java-attribute" : "lastName", "name" : "last-name"}, 
                {"java-attribute" : "phoneNumbers","name" : "phone-number"}
      }, {
         "name" : "PhoneNumber",
         "java-attributes" : {
            "xml-attribute" : [ 
                {"java-attribute" : "type"}
            "xml-value" : [ 
                {"java-attribute" : "number"}
      } ]


<?xml version="1.0"?>
        <java-type name="Customer">
            <xml-type prop-order="firstName lastName address phoneNumbers"/>
                <xml-element java-attribute="firstName" name="first-name"/>
                <xml-element java-attribute="lastName" name="last-name"/>
                <xml-element java-attribute="phoneNumbers" name="phone-number"/>
        <java-type name="PhoneNumber">
                <xml-attribute java-attribute="type"/>
                <xml-value java-attribute="number"/>

Back to the top