You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use case
When using Jackson with Kotlin on Android, the README of this project suggests that at most the two stated proguard rules have to be added, and after that Jackson should just work with features like data classes etc. For me, this was not the case, and most solutions found on StackOverflow and other sources mention that they also use a keep rule for their Kotlin classes that shall be (de-)serialized, or else it won't work. And in fact, only after I added another keep rule did Jackson with Kotlin actually work when running on Android devices. The fact that this requirement was not listed on the official README led me to believe that is was explicitly not required.
Describe the solution you'd like
Add another bullet point to the README that mentions that the classes itself need to be kept with proguard, or else it won't/might not work.
Describe alternatives you've considered
An alternative would be that this is not expected behavior and that in fact it should work with only these two proguard rules. In that case, there might be other problems with how jackson-module-kotlin and R8/proguard interact. My error messages did in fact differ depending on the Android Gradle Plugin version (4.2 and 7) (which determines the proguard / R8 version), but were all either com.fasterxml.jackson.databind.exc.InvalidDefinitionException or java.lang.NoSuchMethodError. Those errors went away the moment I added the rule -keep class my.package.** { *; }.
Additional context
Here is a posts mentioning a rule they use to get jackson-module-kotlin and Proguard to work: https://medium.com/@AthorNZ/kotlin-metadata-jackson-and-proguard-f64f51e5ed32. The rule is -keepclassmembers public class com.mypackage.** { public synthetic <methods>; }. This rule did not work for me, but it might work for others, so a general info about the requirement to also add a keep rule for the classes to (de-)serialize (not just the Metadata annotation) should be appropriate, as it is unspecific enough to apply to different scenarios (versions of proguard/R8 etc.).
The text was updated successfully, but these errors were encountered:
Could you suggest (or PR) some language for the readme that would have been helpful for you? I've never used ProGuard, so what I would come up with is likely to be confusing, at best.
I've created a pull request #494. I can't really claim any certainty when this rule would be needed and when not, but maybe it can help others find out for their case.
Use case
When using Jackson with Kotlin on Android, the README of this project suggests that at most the two stated proguard rules have to be added, and after that Jackson should just work with features like data classes etc. For me, this was not the case, and most solutions found on StackOverflow and other sources mention that they also use a
keep
rule for their Kotlin classes that shall be (de-)serialized, or else it won't work. And in fact, only after I added anotherkeep
rule did Jackson with Kotlin actually work when running on Android devices. The fact that this requirement was not listed on the official README led me to believe that is was explicitly not required.Describe the solution you'd like
Add another bullet point to the README that mentions that the classes itself need to be kept with proguard, or else it won't/might not work.
Describe alternatives you've considered
An alternative would be that this is not expected behavior and that in fact it should work with only these two proguard rules. In that case, there might be other problems with how jackson-module-kotlin and R8/proguard interact. My error messages did in fact differ depending on the Android Gradle Plugin version (4.2 and 7) (which determines the proguard / R8 version), but were all either
com.fasterxml.jackson.databind.exc.InvalidDefinitionException
orjava.lang.NoSuchMethodError
. Those errors went away the moment I added the rule-keep class my.package.** { *; }
.Additional context
Here is a posts mentioning a rule they use to get jackson-module-kotlin and Proguard to work: https://medium.com/@AthorNZ/kotlin-metadata-jackson-and-proguard-f64f51e5ed32. The rule is
-keepclassmembers public class com.mypackage.** { public synthetic <methods>; }
. This rule did not work for me, but it might work for others, so a general info about the requirement to also add akeep
rule for the classes to (de-)serialize (not just the Metadata annotation) should be appropriate, as it is unspecific enough to apply to different scenarios (versions of proguard/R8 etc.).The text was updated successfully, but these errors were encountered: