Creating CollectionType for non generic collection class broken
See original GitHub issueCreation of CollectionType is broken for classes that don’t have generic type parameters since version 2.7.0
Test:
class MyList implements List<Long> {...}
public void testCollectionTypeWithoutGeneric()
{
TypeFactory tf = TypeFactory.defaultInstance();
JavaType t = tf.constructCollectionType(MyList.class, Long.class);
assertEquals(CollectionType.class, t.getClass());
assertSame(Long.class, t.getContentType().getRawClass());
}
So, MyList
is a collection type with Long
as an item type.
Test passes for jackson-databind versions 2.5.x and 2.6.x
For jackson-databind versions 2.7.x and 2.8.x and current master test is broken and throws
java.lang.IllegalArgumentException: Can not create TypeBindings for class com.fasterxml.jackson.databind.type.TestTypeFactory$MyList with 1 type parameter: class expects 0
at com.fasterxml.jackson.databind.type.TypeBindings.create(TypeBindings.java:125)
at com.fasterxml.jackson.databind.type.TypeFactory.constructCollectionType(TypeFactory.java:716)
at com.fasterxml.jackson.databind.type.TypeFactory.constructCollectionType(TypeFactory.java:702)
at com.fasterxml.jackson.databind.type.TestTypeFactory.testCollectionTypeWithoutGeneric(TestTypeFactory.java:565)
You can find ready to merge test case here: https://github.com/Spikhalskiy/jackson-databind/commit/56b018d96e706183dc66b6424f90722b923abd09
Issue Analytics
- State:
- Created 7 years ago
- Comments:15 (10 by maintainers)
Top Results From Across the Web
C# Generic & Non-generic Collections - TutorialsTeacher
C# includes specialized classes that store series of values or objects are called collections. There are two types of collections available in C#:...
Read more >swift - How do I also specify a generic collection type for a ...
Say I am creating a generic class where I would also like to make the collection in which the generic members are stored...
Read more >When to Use Generic Collections | Microsoft Learn
NET Standard 1.0 or later, use the generic collection classes in the System. ... The Builder object can be created by calling the...
Read more >Learn C# with CSharpFritz - Collections and Generics
Fritz is back and teaching C# for beginners. This time we're learning about working with collections of data like arrays and lists.
Read more >Advantages and Disadvantages of Non-Generic Collection in C#
The Non-Generic Collection Classes such as ArrayList, Stack, Queue, Hashtable, SortedList, etc operate on the object data type. As they operate ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mluisbrown Ok good. Apologies for the mess of an API here. It’s not good; it’s just… historical reasons for existence of that (now) unnecessary method. Thank you for pointing it out; at least I can now mark these as properly deprecated.
And maybe @rfoltyns’ patch could also be applied in case you included, since it is semantically similar.
@rfoltyns Glad we improved handling here. In ideal world we’d probably only really have
constructType()
and not many esoteric alternatives; but those are due to pre-2.7 ideas of differences between types. With current type resolution there would be much less need.