Jaxb classes (provided, I cannot change them),
FindResponse.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
})
@XmlRootElement(name = "findResponse")
public class FindResponse {
@XmlElement(required = true)
protected ListWrapper result;
public ListWrapper getResult() {
return result;
}
public void setResult(ListWrapper value) {
this.result = value;
}
}
ListWrapper.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "List", propOrder = {
"any"
})
public class ListWrapper {
@XmlAnyElement(lax = true)
protected java.util.List<Object> any;
public java.util.List<Object> getAny() {
if (any == null) {
any = new ArrayList<Object>();
}
return this.any;
}
}
None of the Jaxb classes wrapped in the ListWrapper class has the @XmlRoolElement annotation (generated from .xsd though, 2000+ classes).
LagInterface.class
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "lag.Interface")
public class LagInterface extends AggregationPortAggregationGroup {
private String objectFullName;
private String displayedName;
private String description;
private Integer lagId;
...
}
Json resource method
@GET
@Path("json/{samoXmlType}")
@Produces(MediaType.APPLICATION_JSON)
public Response jsonGetService(
@PathParam("samoXmlType") String samoXmlType,
@Context HttpServletRequest request,
@Context HttpServletResponse response)
throws Exception
{
LagInterface lag = new LagInterface();
lag.setObjectFullName("lag-interface:1");
lag.setDisplayedName("lag 1");
lag.setDescription("moxy test");
lag.setLagId(1);
FindResponse findResponse = new FindResponse();
ListWrapper result = new ListWrapper();
result.getAny().addAll(Arrays.asList(lag));
findResponse.setResult(result);
return Response.ok(findResponse).build();
}
Response from the above method:
{"result":{}}
The similar XML response:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:findResponse xmlns:ns0="xmlapi_1.0"><ns0:result/></ns0:findResponse>
This is the warning message related to the XML Any collection:
[EL Warning]: XMLAnyCollectionMappingNodeValue: The undefined document root element of a referenced object [XMLDescriptor(LagInterface --> [])] is ignored during marshalling with an any collection|object mapping.