I am using Jackson to deep-copy an object, like so:
Map<String,Object> props = mapper.convertValue(prototype, Map.class);
Command command = mapper.convertValue(props, Command.class);
However, since Command
is an interface without @JsonTypeInfo
attached, this copy fails with error: Can not construct instance of Command.. abstract type
.
I don't want to annotate the interface. I want to provide type information at the conversation level.
How do I do that?
I thought this would work:
mapper.enableDefaultTyping();
Whereby type info would automatically be added for both de/serialization, but I get:
Unexpected token (START_OBJECT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class java.util.Map
So the Map is not getting the type info it needs.