我有一个Android应用程序,它使用Jackson解析器进行JSON解析。在我对这些类运行Proguard之后,我开始在反序列化类的每个成员上获得null
值。
例如,如果我有一个对象:
public class Service{
private String name;
private String version;
... getters, setters and stuff
}
我收到一个包含这些对象列表的JSON:
[{"name":"service1","version":"1.1"},{"name":"service2","version":"1.0"}]
然后我做了:
objectMapper.readValue(jsonString,new TypeReference<List<Service>>() {})
我得到的是一个包含2个Service
个对象的列表,其中所有成员都为空。
有什么想法吗?
由于
我错过了ProGuard警告:
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
修复了以下内容:
-dontskipnonpubliclibraryclassmembers
那就做到了。
亚历
P.S。
这是proguard.conf,所有库都是由Maven插件添加的
-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);
}
答案 0 :(得分:1)
看起来你在一个项目中组合了不同版本的jackson-mapper jar。
jackson-mapper-asl-1.7.9.jar包含
jackson-mapper-asl-1.9.2.jar包含
注意EnumSetDeserializer的不同包以及EnumDeserializer的不同构造函数。 ProGuard无法将1.7.9 EnumSetDeserializer的引用解析为同一类路径上的1.9.2 EnumDeserializer的构造函数,并且它正确地警告它。