[alibaba/fastjson]1.2.70升级到1.2.83后JSON.parseObject 偶尔出现 is not an interface异常

2024-09-02 758 views
7

1.2.70-》1.2.83 后偶然出现 is not an interface 的异常

image

这是代码结构

    public static void main(String[] args) {
    TypeReference<RespData<Detail>> typeReference = new TypeReference<RespData<Detail>>() {};
    String json = "{\"status\":0,\"message\":\"message\",\"data\":{\"test\":\"test\"}}";
    RespData<Detail> respData = parseObject(json, typeReference);
    System.out.println(respData);
  }

  public interface Body {}

  @Data
  static class Detail implements Body {

    private String test;
  }

  @Data
  public static class RespData<T extends Body> {

    /** 状态码,200为成功,其他值为失败. */
    private Integer status;

    /** 本次请求结果信息,如果为错误时,即为详细的错误信息. */
    private String message;

    /** 内容. */
    private T data;
  }

  public static <T extends RespData> T parseObject(String json, TypeReference<T> typeReference) {
    T result = JSON.parseObject(json, typeReference);
    return result;
  }

Originally posted by @AsideIsImp in https://github.com/alibaba/fastjson/issues/4194#issuecomment-1148486377

回答

2

同样的问题,我也遇到了,坑死人拉。

5

这个版本可以试试,虽然最后我们选择了jackson。。。