I am attempting to work through a tutorial from Programmer Bruce that is supposed to allow the deserialization of polymorphic JSON.
The complete list can be found here Programmer Bruce tutorials (Great stuff btw)
I have worked through the first five with no problems but I have hit a snag on the last one (Example 6), which of course is the one I really need to get working.
I am getting the following error at compile time
The method readValue(JsonParser, Class) in the type ObjectMapper is not applicable for the arguments (ObjectNode, Class<capture#6-of ? extends Animal>)
and it's being caused by the chunk of code
public Animal deserialize(
JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
ObjectNode root = (ObjectNode) mapper.readTree(jp);
Class<? extends Animal> animalClass = null;
Iterator<Entry<String, JsonNode>> elementsIterator =
root.getFields();
while (elementsIterator.hasNext())
{
Entry<String, JsonNode> element=elementsIterator.next();
String name = element.getKey();
if (registry.containsKey(name))
{
animalClass = registry.get(name);
break;
}
}
if (animalClass == null) return null;
return mapper.readValue(root, animalClass);
}
}
Specifically by the line
return mapper.readValue(root, animalClass);
Has anyone run into this before and if so, was there a solution?