So, I'm quite new to this Json world and well I'm trying to parse this Json below into a class in java using Gson, but I'm not sure if this is the correct way, because I want this to be a list of maps where the nomeArquivo would be the key in this map, can you guys help me to achive this? Or this way I posted is fine?
Test class
public class JsonTeste {
public static void main(String[] args) {
Gson gson = new Gson();
try (Reader reader = new FileReader("foobar.json")) {
List<FastqcJson[]> list = gson.fromJson(reader, new TypeToken<List<FastqcJson[]>>(){}.getType());
for (FastqcJson[] fastqcJsons : list) {
for (FastqcJson fastqcJson : fastqcJsons) {
System.out.println(fastqcJson);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Bean class
public class FastqcJson {
@SerializedName("name")
private String nomeArquivo;
@SerializedName("data")
private HashMap<Integer, Double> mediaBaseNumeros;
....
}
Printed Objects
FastqcJson [nomeArquivo=SRR3192396, mediaBaseNumeros={1=31.939449600540865, 2=32.05829640249262}]
FastqcJson [nomeArquivo=SRR3192397, mediaBaseNumeros={1=32.01549563582736, 2=32.13918804626231}]
Json File
[ [
{
"color": "#5cb85c",
"data": [
[
1,
31.939449600540865
],
[
2,
32.05829640249262
]
],
"name": "SRR3192396"
},
{
"color": "#5cb85c",
"data": [
[
1,
32.01549563582736
],
[
2,
32.13918804626231
]
],
"name": "SRR3192397"
}
]
]