public class Foo {
@Expose
private ClassA classa;
@Expose
private List<ClassB> list;
}
序列化和反序列化工作正常.但是,当我使用ProGurad混淆我的代码时
我得到以下异常:
com.google.gson.JsonParseException: The Json Deserializer
com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@406f6508
Failed to deserialized json object [{…}, {…}, …] given the type
class java.util.List
解决方法:
您需要在此行中使用GSON正确配置proguard
##---------------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://code.google.com/p/google-gson/source/browse/trunk/examples/android-proguard-example/proguard.cfg