discomarathon / google-gson

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

Maps with interface-type values are not serialized properly #303

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
    @Test
    public final void testInterfaceTypeMap() {
        MapClass element = new MapClass();
        element.addSerializable("Test", "I am invisible!");
        element.addStrings("Test", "I am visible!");
        GsonBuilder builder = new GsonBuilder();
        Gson creator = builder.create();
        String json = creator.toJson(element);
        assertEquals("{\"serializables\":{\"Test\":\"I am invisible!\"},\"strings\":{\"Test\":\"I am visible!\"}}", json);
    }

    static final class MapClass {
        private Map<String, Serializable> serializables = Maps.newHashMap();
        private Map<String, String> strings = Maps.newHashMap();

        public final void addSerializable(final String name, final Serializable value) {
            this.serializables.put(name, value);
        }

        public final void addStrings(final String name, final String value) {
            this.strings.put(name, value);
        }
    }

What is the expected output? What do you see instead?
Expected: {"serializables":{"Test":"I am invisible!"},"strings":{"Test":"I am 
visible!"}}
What I see: {"serializables":{"Test":{}},"strings":{"Test":"I am visible!"}}

What version of the product are you using? On what operating system?
1.6 on Ubuntu Linux

Please provide any additional information below.
Unit test should be sufficient I hope... :)

Original issue reported on code.google.com by chea...@gmail.com on 23 Mar 2011 at 10:21

GoogleCodeExporter commented 9 years ago
Fixed in r776

Original comment by inder123 on 5 Apr 2011 at 11:11