I am trying to map a JSON representation of a list into java classes. I generate my Java using "XSD to Java" and "WADL to Java".
I have the following representation:
JSON:
[
{
"type": "deployment_unit",
"id": 28,
"name": "Tomcat-8080-localhost",
"state": "stopped",
"url": "http://localhost:8080/"
},
{
"type": "deployment_unit",
"id": 4,
"name": "Tomcat-Production",
"state": "stopped",
"url": "foobar"
}
]
I get the JSON object from a web service. The request is correct.
I am not free to modify the XML/JSON representation. I can only modify the XSD files to generate Java. So I have defined a "deployment unit" complex type in xsd. I have also defined a type for "deployment units". this type is just representing a list of "deployment unit" objects.
<xsd:complexType name="DeploymentUnit">
<xsd:sequence>
<xsd:element name="id" type="xsd:int" />
<xsd:element name="name" type="xsd:string" />
<xsd:element name="state" type="DeploymentUnitState" />
<xsd:element name="url" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="DeploymentUnits">
<xsd:sequence>
<xsd:element name="deployment_unit" type="DeploymentUnit" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
I have the following class generated in Java:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DeploymentUnits", propOrder = {"deploymentUnit"})
@XmlRootElement(name = "deployment_units")
public class DeploymentUnits extends AbstractEntityBase
{
@XmlElement(name = "deployment_unit", required = true)
protected List<DeploymentUnit> deploymentUnit;
public List<DeploymentUnit> getDeploymentUnit() {
if (deploymentUnit == null) {
deploymentUnit = new ArrayList<DeploymentUnit>();
}
return this.deploymentUnit;
}
}
My problem is: I always get an empty List after the unmarshalling. JAXB/Jackson seems to don't map the elements correctly and I don't find why.
Note: I have no problem to map only one deployment unit in my java object.
DeploymentUnits units = proxy.getDeploymentUnitResource().search();
System.out.println("Empty list ? -> " + units.getDeploymentUnit().isEmpty()); (always return true :( )
I would like to get a List containing the 2 elements of the JSON array.
Any idea ?
No comments:
Post a Comment