Jackson deserialization ... Unexpected token (END_OBJECT),
As often happens, writing out a question helps you see the solution. So I need to do two things.
Firstly I need to add the type information into the JSON - which is not what I really wanted to do, but I guess you need to provide that information somewhere.
And then I need to edit the annotation on QueryValue to be:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes({ @Type(value = ResourceQueryValue.class, name = "ResourceQueryValue"), @Type(value = NumericQueryValue.class, name= "NumericQueryValue") })
Throwing this out there after having found no solution to this problem. I came up with my own style if it interests anyone who stumbles upon this. Feel free to add your own solutions if you find another way.
I have implemented in my enums to fix this problem has been to add a findByType method that allows you to search on a string representation of the enum key value.So in your example you have an enum with a key/value pair as such,
pubilc enum MyEnum { ...CHIEN("chien", "Chien mechant")...}// Map used to hold mappings between the event key and descriptionprivate static final Map<String, String> MY_MAP = new HashMap<String, String>();// Statically fills the #MY_MAP.static { for (final MyEnum myEnum: MyEnum.values()) { MY_MAP.put(myEnum.getKey(), myEnum); }}
and then you would have a public method findByTypeCode that would return the type for the key you search on:
public static MyEnum findByKey(String pKey) { final MyEnum match = MY_MAP.get(pKey); if (match == null) { throw new SomeNotFoundException("No match found for the given key: " + pKey); } return match;}
I hope this helps. Like I said, there may be a solution out there that tackles this directly, but I haven't found one and don't need to waste more time searching for a solution when this works well enough.