I am trying to wrap my head in POSTing json in a REST service and JAXB namespace. I use Resteasy to tag 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 message and it works:
{ "acme.MultCriteria": { "acme.DateCriteria": { startDate: "2009/01/01", endDate: "2009/01/01" } } }
In the service, I get a MultCriteria object with a single list of DateCriteria items. Oddly enough, I have to pass the namespace in the JSON object, even if I marked the map service with an 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 DateCriteria list. If I modify the DateCriteria object so that it has an empty namespace, then the syntax above works fine.
- , ? ?