users@jersey.java.net

Re: [Jersey] Natural JSON Config Not Giving Me Single Element Arrays

From: Jakub Podlesak <Jakub.Podlesak_at_Sun.COM>
Date: Thu, 19 Nov 2009 16:36:24 +0100

Hi Paul,

Thanks for reporting this. It is definitely a bug.
Filed as [1]. The bad news is, that most probably,
i will need to update jaxb-impl in order to resolve this
in Jersey. For the time being, i hope you could workaround
this by using the mapped notation as you suggested.

~Jakub

[1]https://jersey.dev.java.net/issues/show_bug.cgi?id=427

On Tue, Nov 17, 2009 at 04:10:30PM -0800, Paul Sanders wrote:
> I've followed the instructions I've found to define my own
> JSONJAXBContext with natural build specified but when I output the
> JSON representation for an object that has only single elements in
> their children List:
>
> public class Permission implements Comparable
> {
> private Integer id;
> private String key;
> private String description;
> private Integer featureId;
> private List<Permission> children; // optional, holds the
> children permission of this one
> private String label;
> }
>
> I get the following (my formatting):
>
> [
> {"children": [
> {"children": {
> "description":"Ability to view a tool permission",
> "featureId":1,
> "id":7,
> "key":"admin.perm.edit",
> "label":"edit"},
> "description":"Ability to view a tool permission",
> "featureId":1,
> "id":7,
> "key":"admin.perm.edit",
> "label":"perm"}
> ],
> "description":"Ability to view a tool permission",
> "featureId":1,
> "id":7,
> "key":"admin.perm.edit",
> "label":"admin"}
> ]
>
> The second "children" value is a singleton array but appears without
> the "[" that I was expecting. If I change my context to be mapped but
> specify that "children" is an an array I get this:
>
> {
> "permission": {
> "children": [
> {"children": [
> {"description":"Ability to view a tool permission",
> "featureId":"1",
> "id":"7",
> "key":"admin.perm.edit",
> "label":"edit"
> }],
> "description":"Ability to view a tool permission",
> "featureId":"1",
> "id":"7",
> "key":"admin.perm.edit",
> "label":"perm"
> }],
> "description":"Ability to view a tool permission",
> "featureId":"1",
> "id":"7",
> "key":"admin.perm.edit",
> "label":"admin"}
> }
>
> which is what I would expect - both children arrays are single valued
> but enclosed in "[". I'd really like to use the natural configuration,
> can anyone suggest what I am doing wrong? I'm using 1.1.4 of the
> jersey framework and 2.1.10 of jaxb-impl.
>
> Here are the two lines I used for the configuration....
>
> //this.context = new
> JSONJAXBContext(JSONConfiguration.mapped().arrays("children").build(),
> classes.toArray(new Class[classes.size()]));
> //this.context = new
> JSONJAXBContext(JSONConfiguration.natural().build(),
> classes.toArray(new Class[classes.size()]));
>
> Thanks for any help you can give
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
Jakub Podlešák
Software Engineer at SUN Microsystems And CZJUG Co-Leader
http://blogs.sun.com/japod