You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, using the new sequenced collection types for deserialization (such as the type of a property of a value being deserialized) results in a failure:
Cannot find a deserializer for non-concrete Collection type [collection type; class java.util.SequencedCollection, contains [simple type, class java.lang.String]]
This contrasts with existing collection interfaces (such as List, Queue, SortedMap), which are currently automatically deserialized to a reasonable type (ArrayList, LinkedList, and TreeMap for these specific examples).
Describe the solution you'd like
It would be ideal if properties of the new sequenced interface types could be deserialized from JSON in the same way as the existing collection interface types.
The ideal mappings most in line with the existing ones seem to be:
SequencedCollection: ArrayList
SequencedSet: LinkedHashSet
SequencedMap: LinkedHashMap
Usage example
Here is a JUnit Jupiter test that shows the existing behavior for the pre-Java 21 interface types, and the proposed behavior for the sequenced types.
This is obviously a Java 21 feature. One option is to mirror what is done with Java 8 with jackson-modules-java8 and have a separate module.
Alternatively, I see that deserialization of standard collection interfaces appears to be handled by BasicDeserializerFactory.ContainerDefaultMappings:
Since it looks like BasicDeserializerFactory.ContainerDefaultMappings doesn't require the classes to exist on the classpath, it looks like you could just hardcode the Java 21 types in there:
// 09-Feb-2019, tatu: And more esoteric types added in JDK6fallbacks.put(Deque.class.getName(), LinkedList.class);
fallbacks.put(NavigableSet.class.getName(), TreeSet.class);
// Sequenced types added in JDK21fallbacks.put("java.util.SequencedCollection", DEFAULT_LIST);
fallbacks.put("java.util.SequencedSet", LinkedHashSet.class);
_collectionFallbacks = fallbacks;
}
The text was updated successfully, but these errors were encountered:
Thanks for the report. We will have to have a solution in place for some future version of Jackson. If you want to use Sequence types today, you could try writing a custom deserializer. Jackson is very extensible this way.
Is your feature request related to a problem? Please describe.
Java 21 is adding sequenced collection interfaces
SequencedCollection
,SequencedSet
, andSequencedMap
. These represent collections with a well-defined iteration order, such asList
,SortedSet
,LinkedHashSet
, andLinkedHashMap
.Currently, using the new sequenced collection types for deserialization (such as the type of a property of a value being deserialized) results in a failure:
This contrasts with existing collection interfaces (such as
List
,Queue
,SortedMap
), which are currently automatically deserialized to a reasonable type (ArrayList
,LinkedList
, andTreeMap
for these specific examples).Describe the solution you'd like
It would be ideal if properties of the new sequenced interface types could be deserialized from JSON in the same way as the existing collection interface types.
The ideal mappings most in line with the existing ones seem to be:
SequencedCollection
:ArrayList
SequencedSet
:LinkedHashSet
SequencedMap
:LinkedHashMap
Usage example
Here is a JUnit Jupiter test that shows the existing behavior for the pre-Java 21 interface types, and the proposed behavior for the sequenced types.
Additional context
This is obviously a Java 21 feature. One option is to mirror what is done with Java 8 with jackson-modules-java8 and have a separate module.
Alternatively, I see that deserialization of standard collection interfaces appears to be handled by
BasicDeserializerFactory.ContainerDefaultMappings
:jackson-databind/src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java
Lines 2540 to 2595 in d7e77c3
Since it looks like
BasicDeserializerFactory.ContainerDefaultMappings
doesn't require the classes to exist on the classpath, it looks like you could just hardcode the Java 21 types in there:The text was updated successfully, but these errors were encountered: