FasterXML / jackson-module-kotlin

Module that adds support for serialization/deserialization of Kotlin (http://kotlinlang.org) classes and data classes.
Apache License 2.0
1.12k stars 175 forks source link

Missing type in TypeReference when applying R8 minify/shrink #695

Closed FelipiMatheuz closed 1 year ago

FelipiMatheuz commented 1 year ago

Overview The bug has discovered when I was trying to read a value from api and trying to map into a list of objects. When I was debugging it was OK but when I applied the R8, my called function throwed an exception.

What was intended val mapper = jacksonObjectMapper() val url = URL("$origin$path") mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) val result = mapper.readValue<List>(url) return result

Result ´Internal Error: TypeReference constructed without actual type information´

Expected behavior A list of 'ApiData' objects

Versions Kotlin: 1.8.10 Jackson-module-kotlin:2.15.x (same problem at 2.14.x)

Aditional information I have tried inserting some configuration in proguard-rules file, as I saw in some topics ´-keepattributes Signature´ <- it was the common option to solve, but whatever I did, doesn't work change to subclass using ´TypeReference<List>(){}´ also doesn't work, as caught same error

k163377 commented 1 year ago

If the error only occurs when using R8, then it is probably not a bug in jackson-module-kotlin. I will close it, so please re-open it if you can provide evidence that this is a problem that should be fixed in jackson-module-kotlin.

LJOSS commented 1 year ago

I have same problem for my project Everything is working on debug Build, but Release build make a crash

Im using com.fasterxml.jackson.module:jackson-module-kotlin:2.13.3

What was intended objectMapper.readValue(file)

data class TokenFileResponse is already at proguard-rules.pro file

Result java.lang.IllegalArgumentException: Internal error: TypeReference constructed without actual type information at com.fasterxml.jackson.core.type.TypeReference.(TypeReference.java:35)

Expected behavior Data-class Object from File

Versions AGP 8.1.1 Kotlin 1.8.20 Compile Options Java 17 CompileSDK 34

Aditional information I have tried inserting some configuration in proguard-rules file, as I saw in some topics ´-keepattributes Signature´, and this is not helps me.

k163377 commented 1 year ago

@LJOSS Again, if the problem occurs only when you apply R8, then it is either a problem with R8 or your configuration is wrong. I am not familiar with R8 and suggest you ask the appropriate community.