discomarathon / google-gson

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

Deserialization of List with one item #215

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am using GSON for JSON deserialization and so far it has been a great help.
But I am struggling with an issue with de serialization of List with generic 
and concrete types when the list contains only one element.

For example - 

public class Department {
    public String name;
    public String code;
}

public class Product {

        private List<String> attributes;
        private List<Department> departments;

        public List<String> getAttributes() {
            return attributes;
        }

        public void setAttributes(List<String> attributes) {
            this.attributes = attributes;

        public List<Department> getDepartments() {
            return departments;
        }

        public void setDepartments(List<Department> departments) {
            this.departments = departments;

    }
}

This works fine if either of my list attributes or departments contain more 
than one item in the list.
But if it contains only element in the list - I get an error saying - no valid 
JSON Array

Please help!

Original issue reported on code.google.com by nitin.na@gmail.com on 12 Jun 2010 at 2:04

GoogleCodeExporter commented 9 years ago
I couldn't reproduce this. Please provide a JUnit test case if it continues to 
be a problem.
http://code.google.com/p/google-gson/source/detail?r=582

Original comment by limpbizkit on 27 Aug 2010 at 7:10