gpt4 book ai didi

android - Proguard 的 GSON 反序列化错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:21:12 25 4
gpt4 key购买 nike

我有一个简单的类,其中包含如下列表:

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 类。

##---------------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 ----------

关于android - Proguard 的 GSON 反序列化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21142417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com