Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
GoogleCodeExporter opened this issue Mar 19, 2015 · 3 comments
Closed

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

Fix submitted in r363.

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

  • Changed state: Fixed

@dragontree101
Copy link

how slove this problem? i use gson 2.8.0 , has the same problem

@JordyCuan
Copy link

Hi, I am having the same problem, did anyone knows the solution? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants