Rohan Peshkar Rohan Peshkar - 5 months ago 67
JSON Question

After applying Proguard, Jackson skipping to parse json response with root

I have enabled Proguard and added proper proguard rules for all the libraries I am using.

I use Retrofit for network calls and Jackson converter for parsing responses.

My Json responses have root values, to parse this using Jackson I use setting

SerializationFeature.WRAP_ROOT_VALUE
and
DeserializationFeature.UNWRAP_ROOT_VALUE
. Everything was working till I applied proguard.

Without giving any parsing exceptions the fields are parsed as null values.

The Proguard rules I am using for Jackson are

-keepnames class com.fasterxml.jackson.** { *; }

-dontwarn com.fasterxml.jackson.databind.*

-keepattributes *Annotation*,EnclosingMethod,Signature

-keep class org.codehaus.** { *; }

-keepclassmembers public final enum
org.codehaus.jackson.annotate.JsonAutoDetect$Visibility {
public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *;
}

-keepclasseswithmembers class com.jombay.vger.rx.resources.** {
public protected private <init>(...);
public void set(*);
public ** get*();
}

-keepclasseswithmembers public class com.jombay.vger.retrofit.resources.** {
public protected private <init>(...);
public void set(*);
public ** get*();
}

-keepclasseswithmembers public class com.jombay.vger.utils.** {
public protected private <init>(...);
}

-keepclassmembers class * {
@org.codehaus.jackson.annotate.* *;
}

-keep class com.fasterxml.jackson.databind.ObjectMapper {*;}

-keep class com.fasterxml.jackson.databind.ObjectWriter {*;}


I have come up with this configuration after resolving lot of other issues.

Not able to debug and understand the issue here.

Answer

In your configuration to keep your domain classes, you are missing some wildcards. Instead of this

-keepclasseswithmembers class com.jombay.vger.rx.resources.** {
  public protected private <init>(...);
  public void set(*);
  public ** get*();
}

it should rather be:

-keepclasseswithmembers class com.jombay.vger.rx.resources.** {
  <init>(...);
  public void set*(***);
  public *** get*();
}