vavr-io / vavr-jackson

Jackson datatype module for Vavr
Apache License 2.0
97 stars 35 forks source link

Parsing List of Tuple2 #187

Closed Vance-Turner closed 3 years ago

Vance-Turner commented 3 years ago

Have I stumbled upon on a bug or am I doing the generics wrong?

ObjectMapper mapper = new ObjectMapper().registerModule(new VavrModule());
String json = "[[-1,0.25],[1,0.75]]";
mapper.readValue(json, new TypeReference<Tuple2<Tuple2<Integer,Double>,Tuple2<Integer,Double>>>() {});
mapper.readValue(json, new TypeReference<List<Tuple2<Integer,Double>>>() {});

I would like to parse the JSON above into List<Tuple2<Integer,Double>>. There could be more [int,double] entries; but I've included only two pairs in the example.

The first parsing attempt works; but the second fails:

Unexpected exception thrown: java.lang.IncompatibleClassChangeError: Method 'io.vavr.collection.List io.vavr.collection.List.ofAll(java.lang.Iterable)' must be Methodref constant
org.opentest4j.AssertionFailedError: Unexpected exception thrown: java.lang.IncompatibleClassChangeError: Method 'io.vavr.collection.List io.vavr.collection.List.ofAll(java.lang.Iterable)' must be Methodref constant
    at org.junit.jupiter.api.AssertDoesNotThrow.createAssertionFailedError(AssertDoesNotThrow.java:83)
    at org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:54)
    at org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:37)
    at org.junit.jupiter.api.Assertions.assertDoesNotThrow(Assertions.java:3005)
    at vavrjackson.ParseListTupleTest.doParsing(ParseListTupleTest.java:11)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
    <More stacktrace>
Caused by: java.lang.IncompatibleClassChangeError: Method 'io.vavr.collection.List io.vavr.collection.List.ofAll(java.lang.Iterable)' must be Methodref constant
    at io.vavr.jackson.datatype.deserialize.SeqDeserializer.create(SeqDeserializer.java:68)
    at io.vavr.jackson.datatype.deserialize.SeqDeserializer.create(SeqDeserializer.java:28)
    at io.vavr.jackson.datatype.deserialize.ArrayDeserializer.deserialize(ArrayDeserializer.java:103)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2798)
    at vavrjackson.ParseListTuple.doParsing(ParseListTuple.java:17)
    at vavrjackson.ParseListTupleTest.lambda$doParsing$0(ParseListTupleTest.java:11)
    at org.junit.jupiter.api.AssertDoesNotThrow.assertDoesNotThrow(AssertDoesNotThrow.java:50)
    ... 91 more

I am using:

Vance-Turner commented 3 years ago

Tried a wider variety of types. Interesting, everything works except List:

ObjectMapper mapper = new ObjectMapper().registerModule(new VavrModule());
String json = "[[-1,0.25],[1,0.75]]";
mapper.readValue(json, new TypeReference<Tuple2<Tuple2<Integer,Double>,Tuple2<Integer,Double>>>() {});
mapper.readValue(json, new TypeReference<Array<Tuple2<Integer,Double>>>() {});
mapper.readValue(json, new TypeReference<Queue<Tuple2<Integer,Double>>>() {});
mapper.readValue(json, new TypeReference<List<Tuple2<Integer,Double>>>() {});
ruslansennov commented 3 years ago

hi @Vance-Turner could you test your reproducer with vavr 0.10.3?

Vance-Turner commented 3 years ago

Ah, thanks @ruslansennov. I see there is a 1.0.0-alpha-3 version for Jackson available as well and matching the versions 0.10.3 or 1.0.0-alpha3 works. I thought I had checked that.