Closed Zhang-liangliang closed 2 years ago
小伙子,请提供一下 Bean 类的代码
public class Person implements Serializable {
private String name;
private Integer age;
private String sex;
}
public class Student extends Person implements Serializable {
private String score;
private List
public static class Teacher extends Person implements Serializable {
private String category;
private List<Student> students;
}
public static class Info implements Serializable {
private String address;
private String phone;
}
}
public class DataBean {
private int code;
private String msg;
private Student data;
}
大佬,get和set方法已省略,最外层用DataBean接收。
大佬突然发现Student类里面的泛型会被擦除掉,我重新贴了Student类的截图,请知悉
小伙子,关于解析 Map 无法容错的问题已经处理,你可以下载这个包测试一下。
膜拜大佬,问题解决了,看了你写的MapTypeAdapter
问题描述
框架版本:GsonFactory版本:6.0 gson版本:2.9.0
问题描述:在解析期望类型是LinkedTreeMap<String, String>,实际返回数据可能是null,空字符串,数组等类型,则会报错,具体使用json在相关文件中
复现步骤:集成框架后,解析测试json数据
是否必现:是
出现问题的手机信息:模拟器Pixel 4,小米MI-4C
出现问题的安卓版本:API29
请回答
是部分机型还是所有机型都会出现:测试的机型都出现报错
框架最新的版本是否存在这个问题:是
是否已经查阅框架文档还未能解决的:是
issue 是否有人曾提过类似的问题:否
使用原生的 Gson 是否也会出现该问题:是
其他
提供报错堆栈:
E/CustomActivityOnCrash: App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 1069 path $.data.friends[1].friends[0].extra[0] at com.hjq.gson.factory.element.ReflectiveTypeAdapter.read(ReflectiveTypeAdapter.java:73) at com.google.gson.Gson$FutureTypeAdapter.read(Gson.java:1079) at com.hjq.gson.factory.element.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:34) at com.hjq.gson.factory.element.CollectionTypeAdapter.read(CollectionTypeAdapter.java:62) at com.hjq.gson.factory.element.CollectionTypeAdapter.read(CollectionTypeAdapter.java:23) at com.hjq.gson.factory.element.ReflectiveTypeUtils$1.read(ReflectiveTypeUtils.java:111) at com.hjq.gson.factory.element.ReflectiveTypeAdapter.read(ReflectiveTypeAdapter.java:71) at com.google.gson.Gson$FutureTypeAdapter.read(Gson.java:1079) at com.hjq.gson.factory.element.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:34) at com.hjq.gson.factory.element.CollectionTypeAdapter.read(CollectionTypeAdapter.java:62) at com.hjq.gson.factory.element.CollectionTypeAdapter.read(CollectionTypeAdapter.java:23) at com.hjq.gson.factory.element.ReflectiveTypeUtils$1.read(ReflectiveTypeUtils.java:111) at com.hjq.gson.factory.element.ReflectiveTypeAdapter.read(ReflectiveTypeAdapter.java:71) at com.hjq.gson.factory.element.ReflectiveTypeUtils$1.read(ReflectiveTypeUtils.java:111) at com.hjq.gson.factory.element.ReflectiveTypeAdapter.read(ReflectiveTypeAdapter.java:71) at com.google.gson.Gson.fromJson(Gson.java:991) at com.google.gson.Gson.fromJson(Gson.java:956) at com.google.gson.Gson.fromJson(Gson.java:905) at com.google.gson.Gson.fromJson(Gson.java:876)
提供截图或视频(根据需要提供,此项不强制) 相关文件.zip
提供解决方案(如果已经解决了的话,此项不强制):小白一枚,不知道具体解决思路,只知道可能是AdapterFactory的问题