I have an Android app which uses Jackson parser for JSON parsing. After I've ran Proguard on the classes I started to get null
values on each and every member of the de-serialized classes.
For example, if I have a object:
public class Service{
private String name;
private String version;
... getters, setters and stuff
}
and I receive a JSON with list of those objects:
[{"name":"service1","version":"1.1"},{"name":"service2","version":"1.0"}]
then I do:
objectMapper.readValue(jsonString,new TypeReference<List<Service>>() {})
what I get is a list with 2 Service
objects where all members are null.
Any ideas?
Thanks
UPDATE
I've missed ProGuard warnings:
org.codehaus.jackson.map.deser.EnumSetDeserializer: can't find referenced method 'EnumDeserializer(org.codehaus.jackson.map.deser.EnumResolver)' in class org.codehaus.jackson.map.deser.EnumDeserializer
org.codehaus.jackson.map.deser.impl.StringCollectionDeserializer: can't find referenced method 'org.codehaus.jackson.map.JsonMappingException instantiationException(java.lang.Class,java.lang.Exception)' in class org.codehaus.jackson.map.DeserializationContext
fixed those with:
-dontskipnonpubliclibraryclassmembers
and that did it.
Alex
P.S.
Here's the proguard.conf, all the libraries are added by Maven plugin
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-dontoptimize
-dontnote
-dontskipnonpubliclibraryclasses
-printmapping map.txt
-printseeds seed.txt
-ignorewarnings
-keepclassmembers class * { @com.google.api.client.util.Key <fields>;}
-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault
-keepattributes *Annotation*
-keepclasseswithmembers public class * { public static void main(java.lang.String[]);}
-keepclassmembers public class com.anydo.client.model** { * ; }
-keepclassmembers public class com.anydo.common.dto** { * ;}
-keep class com.j256.** {*;}
-dontskipnonpubliclibraryclassmembers
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
#ACRA
-keep class org.acra.ACRA {
*;
}
# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode { *; }
# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
public void addCustomData(java.lang.String,java.lang.String);
}
# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
public org.acra.ErrorReporter$ReportsSenderWorker handleSilentException(java.lang.Throwable);
}
It looks like you're combining different versions of the jackson-mapper jar in a single project.
jackson-mapper-asl-1.7.9.jar contains
jackson-mapper-asl-1.9.2.jar contains
Notice the different packages for EnumSetDeserializer and the different constructors for EnumDeserializer. ProGuard can't resolve the reference of the 1.7.9 EnumSetDeserializer to the constructor of the 1.9.2 EnumDeserializer on the same class path, and it rightly warns about it.