fyhack / google-gson

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

Map<Integer, Object> has string keys after deserialization #85

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

import java.util.HashMap;
import java.util.Map;

import com.google.gson.Gson;

public class TestGson
{
    Map<Integer, String> map = new HashMap<Integer, String>();

    public static void main(String[] args)
    {
        TestGson testGson = new TestGson();
        testGson.map.put(1, "one");

        Gson gson = new Gson();

        String json = gson.toJson(testGson);
        System.out.println("Json: "+json);

        TestGson testGson2 = gson.fromJson(json, TestGson.class);

        System.out.println("original:");
        System.out.println(testGson.map.containsKey(1));
        System.out.println(testGson.map.containsKey("1"));

        System.out.println("fromJson:");
        System.out.println(testGson2.map.containsKey(1));
        System.out.println(testGson2.map.containsKey("1"));
    }
}

Output:

Json: {"map":{"1":"one"}}
original:
true
false
fromJson:
false
true

What is the expected output? What do you see instead?

The keys should be integers. It should be possible to check the generic
types of the map and then assign the values accordingly. 

What version of the product are you using? On what operating system?
GSON 1.2.3

Original issue reported on code.google.com by nit...@googlemail.com on 29 Dec 2008 at 7:53

GoogleCodeExporter commented 9 years ago
Fix submitted in r363.

Original comment by joel.leitch@gmail.com on 6 Jan 2009 at 7:11