users@jersey.java.net

[Jersey] Re: Jetty and Tomcat different behaviors when returning JSON array

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Mon, 13 Dec 2010 10:43:11 +0100

Hi,

Are different versions of JAXB present in the class path for Jetty and
Tomcat?

Paul.


On Dec 6, 2010, at 10:38 PM, Jason Erickson wrote:

> I have a method (a few actually, but this will do for an example):
>
> @GET
> @Produces(MediaType.APPLICATION_JSON)
> public Observation[] getObservations(
> @QueryParam("startDate") Date startDate,
> @QueryParam("endDate") Date endDate,
> @QueryParam("observerId") Long observerId,
> @QueryParam("observerName") String observerName,
> @QueryParam("subjectId") Long subjectId,
> @QueryParam("subjectName") String subjectName,
> @QueryParam("phenomenonId") Long phenomenonId,
> @QueryParam("page") @DefaultValue("0") int page,
> @QueryParam("pageSize") @DefaultValue("25") int pageSize) {
> ObservationCriteria criteria = new ObservationCriteria();
> criteria.setStartDate(startDate);
> criteria.setEndDate(endDate);
> criteria.setPage(page);
> criteria.setPageSize(pageSize);
> criteria.setObserverId(observerId);
> criteria.setObserverName(observerName);
> criteria.setSubjectId(subjectId);
> criteria.setSubjectName(subjectName);
> criteria.setPhenomenonId(phenomenonId);
> List<Observation> obsResult =
> observationDao.getByCriteria(criteria);
> return obsResult.toArray(new Observation[] {});
> }
>
>
> The data I get back is correct. However, when I deploy the
> application in jetty, the response is returned as a JSON object with
> one named field that contains the array like:
> {"observation": [{"id":"440", "date":"2010-10-28"},{"id":"308",
> "date":"2010-10-28"}]}
>
> When I deploy the same application to tomcat 6, the response is
> returned as a JSON array like:
> [{"id":"440", "date":"2010-10-28"},{"id":"308", "date":"2010-10-28"}]
>
> Is this a bug? Is there a workaround?