JamesDeCarlo / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

add support for "maybe-lists" #384

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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