question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating CollectionType for non generic collection class broken

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, May 17, 2017

@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.

0reactions
cowtowncodercommented, May 19, 2017

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found