I have an object which has a map inside it:
MyDTO
HashMap<Integer>
Now when I convert my MyDTO to JSON (with Gson), and then back from JSON to MyDTO what I get is HashMap<String>.
I convert from JSON back to object like this:
MyDTO dto = gson.fromJson(json, MyDTO.class);
How can I force it to convert/keep the Map inside the DTO as Map<Integer> and NOT as Map<String>?
Here is my Object:
public class MultiSeriesTimebasedChartDTO implements Serializable
{
LinkedHashMap<String, ArrayList<Number>> data;
}
Here's how I convert my JSON back to object:
multiSeriesTimebasedChartDTO = gson.fromJson(json, MultiSeriesTimebasedChartDTO.class);
And here is the result (in screenshot), which were Numbers but now are Strings. I needed them back as Numbers.
So looking for a clean approach for this.
I can definitely iterate over it, change every number from string back to number, and replace it... But I was thinking may be there is some other better way of oing it.

Map<Integer>is not a valid Java type, since aMaprequires 2 type arguments. Did you meanMap<String, Integer>or perhapsMap<Integer, Integer>? Normally, aMapis converted to a JSON Object, and since a JSON Object is a set of name/value pairs, the keys in theMapare converted to strings, because JSON property names must be strings. Is that what you're referring to?