I'm trying to get each of the objects that make up a List of objects so that when I iterate over them I'll add them to a database.
The procedure I follow is the following:
1. I call this method that converts a Json string to a list of objects.
public List<Schedule> jsonStringToArray(String jsonString) throws IOException {
return OBJECT_MAPPER.readValue(jsonString, /*new TypeReference<List<Schedule>>(){}*/ List.class);
//return OBJECT_MAPPER.convertValue(schedules, new TypeReference<List<Schedule>>() {});
}
Itero and I get each object to add it in the database
for (int i = 0; i < schedules.getSchedulesList().size(); i++) {
scheduleService.saveSchedule(schedules.getSchedulesList().get(i));
System.out.println(schedules.getSchedulesList().get(i));
}
The fault gives me on the save line and tells me the following:
java.lang.ClassCastException: java.util.LinkedHashMap can not be cast to en.ticnor.trayecbus.model.Schedule
I think the error is in the jsonStringToArray method, when doing the return I'm not doing the mapper well in such a way that it becomes a Schedule object. What I think this is doing is in a kind of auxiliary object of type LinkedHashMap