users@jersey.java.net

RE: Set the root when returning a collection

From: Jeremy Whitlock <jwhitlock_at_collab.net>
Date: Wed, 12 Nov 2008 14:15:00 -0800

For posterity, below is some example output:

XML Output
----------
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<People>
  <person>
    <age>27</age>
    <firstName>Jeremy</firstName>
    <lastName>Whitlock</lastName>
  </person>
.....

JSON Output
-----------
{"person":
  [{
      "age":"27",
      "firstName":"Jeremy",
      "lastName":"Whitlock"
   },
.....

And just to summarize what is going on that seems out of place:

1) In XML, Jersey assumes that the root node should be capitalized.
2) In JSON, there is no "name" for each person object in the array.
3) In JSON, the root is not plural.

And finally, what I'm proposing is a configurable way to handle these
situations. I don't have any implementation suggestions at this time
other than to propose some sort of runtime-based configuration like a
property or something.