Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Note:</strong> I'm the <a href="http://www.eclipse.org/eclipselink/moxy.php" rel="nofollow"><strong>EclipseLink JAXB (MOXy)</strong></a> lead, and a member of the <a href="http://jcp.org/en/jsr/detail?id=222" rel="nofollow"><strong>JAXB 2 (JSR-22)</strong></a> expert group.</p> <p>The MOXy component in EclipseLink 2.4 will contain the type of JSON binding you are looking for. In the example below an Address object is mapped to the response of running <a href="http://code.google.com/apis/maps/documentation/geocoding/v2/" rel="nofollow">Google's Geocoding API V2</a>. This example demonstrates how the path based mapping eliminates the need to for close relationship between classes and JSON structure.</p> <pre><code>package blog.geocode.json; import javax.xml.bind.annotation.XmlType; import org.eclipse.persistence.oxm.annotations.XmlPath; @XmlType(propOrder={"country", "state", "city", "street", "postalCode"}) public class Address { @XmlPath("Placemark/ns:AddressDetails/ns:Country/ns:AdministrativeArea/ns:Locality/ns:Thoroughfare/ns:ThoroughfareName/text()") private String street; @XmlPath("Placemark/ns:AddressDetails/ns:Country/ns:AdministrativeArea/ns:Locality/ns:LocalityName/text()") private String city; @XmlPath("Placemark/ns:AddressDetails/ns:Country/ns:AdministrativeArea/ns:AdministrativeAreaName/text()") private String state; @XmlPath("Placemark/ns:AddressDetails/ns:Country/ns:CountryNameCode/text()") private String country; @XmlPath("Placemark/ns:AddressDetails/ns:Country/ns:AdministrativeArea/ns:Locality/ns:PostalCode/ns:PostalCodeNumber/text()") private String postalCode; } </code></pre> <ul> <li><a href="http://blog.bdoughan.com/2011/08/binding-to-json-xml-geocode-example.html" rel="nofollow">http://blog.bdoughan.com/2011/08/binding-to-json-xml-geocode-example.html</a> (Full Example)</li> </ul> <p>As you mention having a separate mapping document is key to applying multiple mappings to an object model. The MOXy binding document can be leveraged for both XML and JSON binding:</p> <ul> <li><a href="http://blog.bdoughan.com/2011/09/mapping-objects-to-multiple-xml-schemas.html" rel="nofollow">http://blog.bdoughan.com/2011/09/mapping-objects-to-multiple-xml-schemas.html</a></li> </ul> <p>You can try the JSON binding out today using one of the milestone builds:</p> <ul> <li><a href="http://www.eclipse.org/eclipselink/downloads/milestones.php" rel="nofollow">http://www.eclipse.org/eclipselink/downloads/milestones.php</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload