shau-lok/google-gson

add support for "maybe-lists"

Closed this issue · 2 comments

hello everyone,

sometimes when i request my service depending on query parameters it can return 
something like this:

{
    "retorno":[
        {
            "comment":"comment A",
            "id":"7"
        },
        {
            "comment":"comment B",
            "id":"13"
        }
    ]
}

and sometimes like this:

{
    "retorno":{
        "comment":"comment C",
        "id":"6"
    }
}

and my class seems like this:

public class CommentReturn {

    private List<Comment>comment;

    public List<Comment>getComment(){
        return comment;
    }

    public void setComment(List<Comment> comment){
        this.comment=comment;
    }
}

this is generated by a jaxb backend, but had no success generating always the 
list even when there is only one result.

this is not a gson problem... but would be nice to have a way to always feed 
the class correctly, even when it have an object instead a list... but is the 
correct generic type. 

Original issue reported on code.google.com by Sombr...@gmail.com on 6 Dec 2011 at 2:40

An small uppdate: even jackson which is used by jersey to generate such odd 
json does not handle well this own result. At least in the default setup.

please forget it and close, i'll try something else.

Original comment by Sombr...@gmail.com on 6 Dec 2011 at 3:39

Original comment by limpbizkit on 6 Dec 2011 at 4:12

  • Changed state: WontFix