// File subclass.java
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
public class subclass {
static class A {
List<Vehicle> vehicles = new ArrayList();
}
static class Vehicle {
String type;
Vehicle (String type) {
this.type = type;
}
}
static class Car extends Vehicle {
String make;
Car (String make) {
super("Car");
this.make = make;
}
}
static class Honda extends Car {
String model;
public Honda (String model) {
super("Honda");
this.model = model;
}
}
public static void main(String[] args) {
A a = new A();
a.vehicles.add(new Honda("Civic"));
a.vehicles.add(new Honda("Accord"));
a.vehicles.add(new Car("Toyota"));
a.vehicles.add(new Vehicle("Truck"));
System.out.println(new Gson().toJson(a));
}
}
$ javac -cp gson-2.1.jar subclass.java
$ java -cp .:gson-2.1.jar subclass
{"vehicles":[{"model":"Civic","make":"Honda","type":"Car"},{"model":"Accord","make":"Honda","type":"Car"},{"make":"Toyota","type":"Car"},{"type":"Truck"}]}
Am I misunderstanding your problem?
> --
> You received this message because you are subscribed to the Google Groups "google-gson" group.
> To post to this group, send email to googl...@googlegroups.com.
> To unsubscribe from this group, send email to google-gson...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-gson?hl=en.
>
http://code.google.com/p/google-gson/issues/detail?id=43#c15