3

I'm facing an issue with Jackson and Kotlin Data classes when enabling Proguard. Jackson version: 2.9.1 Jackson Converter version: 2.3.0 Kotlin version: 1.2.51

Here's my proguard file:

-ignorewarnings

    # Jackson 2.x
-keepclassmembers class com.jgarin.remote.models.** {
  <init>(...);
  <fields>;
}
-keepclassmembers class * {
     @com.fasterxml.jackson.annotation.JsonCreator *;
     @com.fasterxml.jackson.annotation.JsonProperty *;
}

#Required for Kotlin!
-keep class kotlin.Metadata { *; }
-keep class kotlin.reflect.** { *; }
-keepclassmembers public class com.jgarin.** {
    public synthetic <methods>;
}

-keepattributes SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,Signature,Exceptions,InnerClasses

Still, the app fails, throwing an exception:

E/RxCallAdapterWrapper: Retrofit exception occurred
    com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.jgarin.remote.models.responses.GetVerificationCodeResponse` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)

The rest of the stack trace is pretty much useless. I'm pretty sure I'm missing something obvious. Any help is appreciated. Thank you.

1 Answers1

-1

I think you need a no-args constructor in your classes to allow jackson to instanciate your class. Like this:

class AFHResponse(val MESSAGE: String, val CODE: String, val MIRRORS: Array<Mirror>) {
    private constructor() : this("", "", emptyArray())
}

Example from here

Vaccano
  • 78,325
  • 149
  • 468
  • 850
binarynoise
  • 364
  • 3
  • 14
  • Thank you for the answer and welcome to Stack Overflow! Generally, Stack Overflow prefers answers that include the relevant data and code from links that are provided (in case the link goes offline in future years.) Consider adding the linked code as a sample in the answer and then referencing (via the link) where you got it from. – Vaccano Dec 13 '19 at 00:44