Skip to content

unable to serialize an object with list of other objects #170

Closed

Description

@GoogleCodeExporter
interface IPerson {
  String getName();
}

public class Person implements IPerson {
  private String name;
  public Person() { 
  } 
  public Person(String name) {
    this.name = name;
  }
  @Override
  public String getName() {
    return name;
  }
}

public class People {
  private List<IPerson> people = new LinkedList<IPerson>();
  public People() {
  }
  public People(List<IPerson> people) {
    this.people = people;
  }
  public List<IPerson> getPeople() {
    return people;
  }
}

@Test
public void testGsonProjects() {
  People people = new People(asList((IPerson) new Person("Obama")));
  String json = new Gson().toJson(people);  
  System.out.println(json);
}

expected: {people:[{name:"Obama"}]}
actual  : {people:[{}]}

affected version: 1.3, 1.4

Original issue reported on code.google.com by luca.marrocco on 30 Oct 2009 at 11:33

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions