g-6ren">
gpt4 book ai didi

java - 为什么 Retrofit & Gson 返回一个 LinkedTreeMap 列表而不是我预期的类型?

转载 作者:行者123 更新时间:2023-11-29 19:06:36 24 4
gpt4 key购买 nike

我正在尝试通过 Retrofit 检索对象列表:

public interface TemplateApi {
@GET("/api/templates")
Observable<List<TemplateDto>> getList();
}

这里是 Dto:

public class TemplateDto {
public String id;
public String name;

@Override
public String toString() {
return this.name;
}
}

我得到的不是预期的列表

List<LinkedTreeMap>

这会导致奇怪的副作用(在我的例子中 toString() 返回的不是我所期望的)

最佳答案

好吧,我发现了——Android 确实没有最平坦的学习曲线...

问题不在于 Retrofit 或 Gson 本身,而在于缩小器 (Proguard)。Proguard 需要在默认名为“proguard-rules.pro”的文件中进行配置。

添加以下行:

-keepattributes Signature
-keepattributes *Annotation*
-keep class com.myproject.dtos.** { *; }

感谢this answer .

关于java - 为什么 Retrofit & Gson 返回一个 LinkedTreeMap 列表而不是我预期的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46998433/

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