我有一个简单的类,其列表如下:
public class Foo {
@Expose
private ClassA classa;
@Expose
private List<ClassB> list;
}
序列化和反序列化工作很好。但是,当我用ProGurad混淆我的代码时,我会得到以下异常:
Json反序列化器com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@406f6508未能反序列化json对象{.}、{.}、.给定类型类java.util.List
发布于 2014-01-16 02:45:40
您需要将这些行添加到您的程序保护程序中,以便在您的应用程序签名时保留gson类。
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
##---------------End: proguard configuration for Gson ----------
发布于 2014-01-15 08:25:32
您需要在这一行使用GSON正确地配置pro卫士。
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
https://stackoverflow.com/questions/21142417
复制