I’ve a problem when I try to map a JSON file to a Object with Jackson Library, I’ve tried a lot of things but it still doesn’t work.
This is my JSON file:
{
2: {
1: {
cuota: "25092.87",
var12m: "-4.01",
var1m: "4.23"
},
2: {
cuota: "23319.83",
var12m: "-0.63",
var1m: "3.33"
},
3: {
....
}
},
3: { ..... }
My Object in Java is this:
public class AfpsDetalles {
private String key;
private HashMap<Integer, Fondos> fondos = new HashMap<Integer, Fondos>();
public static class Fondos{
private float cuota;
private float var12m;
private float var1m;
}
}
And when I map the object I use this:
HashMap<Integer,AfpsDetalles> afpDetalle = mapper.readValue(JSON FILE, new TypeReference<HashMap<Integer,AfpsDetalles>>() {});
Jackson error said that is a problem with the first “1”. Please any help will be apprecied.
That is not valid JSON. JSON property names must be Strings, and Strings are surrounded in double-quotes. So first thing is to fix this problem.