0

Issue details: RestEasy + Jettison

When array has two elements the format is :

{"MyArray" : {"Array" : [{"a" : 1, "b" : 2}, {"a" : 3, "b" : 4}]}}

but when the array has single element, the format is :

{"MyArray" : {"Array" : {"a" : 1, "b" : 2}}} ***Missing the []

RestEasy uses the Jettison Mapped format by default which has a known limitation of list of single elements not being returned as an array. As per this discussion, the proposed solution is to use Jackson, but if that is not an option, is there a way to use RestEasy + Jettison and get around the single element array issue?

Jersey has a solution for this issue which uses JSONJAXBContext but how do I fix this in RestEasy?

musefan
  • 47,875
  • 21
  • 135
  • 185

1 Answers1

0

You may try StAXON instead of Jettiison - http://beckchr.github.com/staxon/

With StAXON you can provide paths to array elements. The wiki has an example: https://github.com/beckchr/staxon/wiki/Using-JAX-RS

chris
  • 3,573
  • 22
  • 20
  • 1
    Thanks for your reply... But if I could move away from Jettison, it would be an easy solution. Unfortunately we are stuck with Jettison and want to resolve the bug instead. Any thoughts? – user1028365 Dec 06 '11 at 16:47
  • 1
    Why are you stuck with Jettison? All you would have to do is to add a @JsonXML annotaton to your model class (or resource method) which lists "/Array" as area path. – chris Dec 06 '11 at 22:32