I have been trying to wrap my head around POSTing json to a REST service and JAXB namespaces. I am using Resteasy to mark up the server side method. I have the following service:
@POST
@Mapped(namespaceMap={@XmlNsMap(namespace="http://acme.com", jsonName=""))
@Path("/search")
@Consumes("application/json")
public List<I> search(SearchCriteria crit);
I have the following objects:
@XmlRootElement(namespace="http://acme.com")
public class DateCriteria {
@XmlElement
private Date start;
@XmlElement
private Date end;
}
@XmlRootElement(namespace="http://acme.com")
public class MultCriteria {
@XmlElementRefs({@XmlElementRef(type=DateCriteria.class)})
private List<DateCriteria> dateCriterias;
}
I can send the following JSON in a post and it works:
{ "acme.MultCriteria": { "acme.DateCriteria": { startDate: "2009/01/01", endDate: "2009/01/01" } } }
On the service, I get a MultCriteria object with a single element list of DateCriteria's. Strangely, I have to pass the namespace in the JSON object even though I marked the service with a map to the empty namespace.
If I try to send an array as follows:
{ "acme.MultCriteria": { "acme.DateCriteria": [ { startDate: "2009/01/01", endDate: "2009/01/01" }, { startDate: "2009/01/01", endDate: "2009/01/01" } ] } }
I get a MultCriteria object with an empty List of DateCriteria. If I modify the DateCriteria object so that it has an empty namespace, then the above syntax works fine.
Does anyone see what I am doing wrong here? How should the namespaces be setup and how do I properly pass them in to the service?