I've got multiple console logs. The "AB" log in the ArrayBuilder itself gives me the output below which is the correct output. But the log in the input for the ArrayBuilder gives me a blank [ ]. Why is the JsonArrayBuilder not returning the correct output?
"AB[{"ingredientnaam":"Banaan","calorieen":89,"vet":0.9,"verzadigd_vet":0.3,"eiwit":1.2,"koolhydraten":20.4,"vezels":1.9,"zout":0.0}]"
Input for the ArrayBuilder
JsonArray ingredientArray = buildJsonIngredientArray(service.getToday(gebruikersnaam, datum));
System.out.println(ingredientArray.toString());
return ingredientArray.toString();
My JsonArrayBuilder
private JsonArray buildJsonIngredientArray(List<Dagboek> list) {
JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
for (Dagboek d : list) {
Ingredient c = d.getIngredient();
JsonObjectBuilder job = Json.createObjectBuilder();
job.add("ingredientnaam", c.getIngredientnaam());
job.add("calorieen", c.getCalorieen());
job.add("vet", c.getVet());
job.add("verzadigd_vet", c.getVerzadigd_vet());
job.add("eiwit", c.getEiwit());
job.add("koolhydraten", c.getKoolhydraten());
job.add("vezels", c.getVezels());
job.add("zout", c.getZout());
jsonArrayBuilder.add(job);
}
System.out.println("AB" + jsonArrayBuilder.build());
return jsonArrayBuilder.build();
}
build. Try storing the return value for build used here:System.out.println("AB" + jsonArrayBuilder.build());, and returning it. (full disclosure, no idea if this will work)