how to convert LinkedHashMap to Custom java object?
import:
import com.fasterxml.jackson.databind.ObjectMapper;
object:
private ObjectMapper mapper = new ObjectMapper();
examples:
PremierDriverInfoVariationDTO premierDriverInfoDTO =
mapper.convertValue(json, PremierDriverInfoVariationDTO.class);
log.debug("premierDriverInfoDTO : {}", premierDriverInfoDTO);
or
Map<String, Boolean> map = mapper.convertValue(json, Map.class);
log.debug("result : {}", map);
assertFalse(map.get("eligiblePDJob"));
You need to do this:
List<ConsultantDto> myObjects =
mapper.readValue(jsonInput, new TypeReference<List<ConsultantDto>>(){});
(From this SO answer)
The reason you have to use TypeReference
is because of an unfortunate quirk of Java. If Java had a proper generics, I bet your syntax would have worked.