Note that there are some explanatory texts on larger screens.

plurals
  1. POI am having problems annotating model classes to support desired XML unmarshalling
    primarykey
    data
    text
    <p>I am interested in using a OXM framework to support unmarshalling of the following XML that will be passed as the HTTP POST payload of a request to a RESTful API call.</p> <p>This is my first time trying to use a OXM framework and I am having problems annotating my model classes correctly. I am using Spring 3.0 and the JAXB2 Marshaller, but I am indifferent as to the specific marshaller implementation.</p> <p>Questions:</p> <p>1) What is the best strategy for annotating my model classes to reflect my desired XML structure? I have an example of how I have been annotating my classes below, and it is resulting in <code>Class has two properties with the same name "XXX"</code> for my XmlElements when I try to create the Marshaller.</p> <p>2) What strategy can I take to support in my annotations and classes? I was defining SpatialExtent as an interface and then the class that implements a GeoBoundingBox XmlElement implemented this interface. This works for Java but not for JAXB.</p> <p>3) Are there any places where the desired XML can be improved to simplify marshalling/unmarshalling?</p> <p>Any help is appreciated! --Stephan</p> <p>Background:</p> <p>Here is an example of the XML I would like to consume:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;AnalysisSettings&gt; &lt;service id="urn:nasa:giovanni:latlonplot"/&gt; &lt;spatialExtent&gt; &lt;GeoBoundingBox&gt; &lt;south&gt;20.0&lt;/south&gt; &lt;north&gt;90.0&lt;/north&gt; &lt;west&gt;0.0&lt;/west&gt; &lt;east&gt;180.0&lt;/east&gt; &lt;/GeoBoundingBox&gt; &lt;/spatialExtent&gt; &lt;temporalExtent&gt; &lt;TimePeriod&gt; &lt;startTime&gt;2008-01-01T00:00:00Z&lt;/startTime&gt; &lt;endTime&gt;2008-01-31T00:00:00Z&lt;/endTime&gt; &lt;/TimePeriod&gt; &lt;/temporalExtent&gt; &lt;variables&gt; &lt;Variable&gt; &lt;dataset id="urn:nasa:modis:MYD08_D3.005"/&gt; &lt;parameter id="urn:nasa:modis:Optical_Depth_Land_And_Ocean_Mean"/&gt; &lt;/Variable&gt; &lt;Variable&gt; &lt;dataset id="urn:nasa:modis:M0D08_D3.005"/&gt; &lt;parameter id="urn:nasa:modis:Optical_Depth_Land_And_Ocean_Mean"/&gt; &lt;/Variable&gt; &lt;/variables&gt; &lt;/AnalysisSettings&gt; </code></pre> <p>GeoBoundingBox and TimePeriod are not the only possible types for spatial and temporal extents, but I have not had to define any other types as of yet.</p> <p>I am using Spring package annotations.</p> <p>An example of how I have been annotating my model classes:</p> <pre><code>@XmlRootElement @XmlType(name="AnalysisSettings") public class AnalysisSettings { @XmlElement(name="service") private Service service; @XmlElement(name="spatialExtent") private SpatialExtent spatialExtent; @XmlElement(name="temporalExtent") private TemporalExtent temporalExtent ; @XmlElement(name="variables") private Variable[] variables; // standard getter and setter methods... } </code></pre> <p>All XmlElements annotations are on class methods that reference model objects and all XmlAttribute annotations are on class methods that reference datatypes (e.g. <code>private String id</code>).</p> <p>I have an early XSD:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;xsd:element name="AnalysisSettings" type="AnalysisSettingsType" /&gt; &lt;xsd:complexType name="AnalysisSettingsType"&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="service" type="serviceType" /&gt; &lt;xsd:element name="spatialExtent" type="spatialExtentType" /&gt; &lt;xsd:element name="temporalExtent" type="temporalExtentType" /&gt; &lt;xsd:element name="variables" type="variablesType" /&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;xsd:complexType name="variablesType"&gt; &lt;xsd:sequence&gt; &lt;xsd:element maxOccurs="unbounded" name="Variable" type="variableType" /&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;xsd:complexType name="variableType"&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="dataset" type="datasetType" /&gt; &lt;xsd:element name="parameter" type="parameterType" /&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;xsd:complexType name="parameterType"&gt; &lt;xsd:attribute name="id" type="xsd:anyURI" /&gt; &lt;/xsd:complexType&gt; &lt;xsd:complexType name="datasetType"&gt; &lt;xsd:attribute name="id" type="xsd:anyURI" /&gt; &lt;/xsd:complexType&gt; &lt;xsd:complexType name="temporalExtentType"&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="TimePeriod" type="TimePeriodType" /&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;xsd:complexType name="TimePeriodType"&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="startTime" type="xsd:dateTime" /&gt; &lt;xsd:element name="endTime" type="xsd:dateTime" /&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;xsd:complexType name="spatialExtentType"&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="GeoBoundingBox" type="GeoBoundingBoxType" /&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;xsd:complexType name="GeoBoundingBoxType"&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="south" type="xsd:decimal" /&gt; &lt;xsd:element name="north" type="xsd:decimal" /&gt; &lt;xsd:element name="west" type="xsd:decimal" /&gt; &lt;xsd:element name="east" type="xsd:decimal" /&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;xsd:complexType name="serviceType"&gt; &lt;xsd:attribute name="id" type="xsd:anyURI" /&gt; &lt;/xsd:complexType&gt; &lt;/xsd:schema&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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