I\'m trying to simplify my code: I want to store key and values (all strings).
I\'m actually using a Map
to store it. hat way
Assuming that your end goal is just to deserialize JSON into a Map<String, Object>
, there is a far simpler way to do this with Jackson. Using ObjectMapper
:
final String json = "{}";
final ObjectMapper mapper = new ObjectMapper();
final MapType type = mapper.getTypeFactory().constructMapType(
Map.class, String.class, Object.class);
final Map<String, Object> data = mapper.readValue(json, type);
You will need error handling etc, but this is a good starting point.