jackson-databind: Creating CollectionType for non generic collection class broken
Creation 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
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (10 by maintainers)
Commits related to this issue
- add a failing test for #1415 — committed to FasterXML/jackson-databind by cowtowncoder 7 years ago
- Fixes #1415 Allow no-type variables in TypeFactory.constructCollection- and MapType — committed to rfoltyns/jackson-databind by rfoltyns 7 years ago
@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.