android – 与proguard的GSON反序列化错误

我有一个简单的类,列表如下:

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

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...