Attempted to serialize java.lang.Class. Forgot to register a type adapter?

问题:Attempted to serialize java.lang.Class. Forgot to register a type adapter?
原因:Gson不支持类信息,序列化和返序列化
解决方案:

  1. 使用Gson的 excluedFieldsWithoutExposeAnnotation() 选项忽略这些字段
    Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); String json=gson.toJson(data);

  2. 用@Expose注释修改类(就是你的实体类),以指示应序列化哪些字段

  3. 自定义序列化类