-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
JsonDeserialize(contentAs=...) doesn't seem to be honored if used with raw collections.
In the following example I would expect that the items field would be deserialized as the MyItem class but instead comes out as a java.util.LinkedHashMap
. Adjusting the following example from List
to List<Object>
causes things to work as expected. (I tried it in 2.9.10 and 2.10.1)
public static class MyCollection {
@JsonDeserialize(contentAs = MyItem.class)
public List items;
}
public static class MyItem {
public String name;
}
public static void main(String[] args) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
MyCollection myCollection =
objectMapper.readValue("{\"items\": [{\"name\":\"item1\"}]}", MyCollection.class);
System.out.println(myCollection.items);
System.out.println(myCollection.items.get(0).getClass());
}
[{name=item1}]
class java.util.LinkedHashMap
I initially encountered this while doing some dynamic class creation via a refineDeserializationType
method in a custom AnnotationIntrospector
which caused the type from the subclass to be lost.
Metadata
Metadata
Assignees
Labels
No labels