discomarathon / google-gson

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

issue with extends class #321

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

i have notice that the current example

public class gsonTest {

    public static void main(String[] args) {
        Response r = new Response().add(new B()).add(new A());
        Gson gson = new GsonBuilder().create();
        System.out.println(gson.toJson(r, r.getClass()));
    }

    public static class Response {
        Vector<A> a = new Vector<A>();
        public Response add(A aa) {

            a.add(aa);
            return this;
        }

    }
    public static class A {
        int A = 1;

    }

    public static class B extends A {
        int B = 2;
    }
}

produce
{"a":[{"A":1},{"A":1}]}

instead
{"a":[{"A":1},{"A":1,"B":2}]}

tested on mac/linux/win 1.6 jvm and 1.7.1 gson lib.

Original issue reported on code.google.com by ramarr...@gmail.com on 4 May 2011 at 1:47

GoogleCodeExporter commented 9 years ago
321 is a duplicate of 231.

Original comment by limpbizkit on 4 May 2011 at 9:31