Complex json string and I want to convert it to a map,
I have a problem.
Take a look at this simple test:
public class Test {
@SuppressWarnings("serial")
public static void main(String[] args) {
Map<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("data", "{\"rowNum\":0,\"colNum\":2,\"text\":\"math\"}");
Map<String,Object> dataMap = JsonUtil.getGson().fromJson(
hashMap.get("data").toString(),new TypeToken<Map<String,Object>>() {}.getType());
System.out.println(dataMap.toString());
}
}
Result:
console printing: {rowNum=0.0, colNum=2.0, text=math}
Int converts to Double,
Why does gson change type and how to fix it?
source
share