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
Original issue reported on code.google.com by
nit...@googlemail.com
on 29 Dec 2008 at 7:53