微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐