Skip to content

Clarify usage for proguard/R8 in README #488

@MaxMello

Description

@MaxMello

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions