反序列化多层嵌套json实体

方法

import com.alibaba.fastjson.JSONObject;

import com.alibaba.fastjson.TypeReference;

import com.fasterxml.jackson.annotation.JsonInclude;

import com.fasterxml.jackson.core.JsonProcessingException;

import com.fasterxml.jackson.databind.ObjectMapper;


 public static UserInfoResponse parse(String json, Class clazz){

    return JSONObject.parseObject(json,new TypeReference>(clazz){});

  }

实体关系

public class UserInfoResponse implements Serializable {

  private String code;

  private String status;

  private String msg;

  private String count;

  private T responsebody;

}

public class User {

  private String name;

  private String organization;

  private String position;

}

反序列化调用

UserInfoResponse userInfoResponse = JSON.parse(json, User.class);

参考详细链接:https://www.cnblogs.com/liqipeng/p/9148545.html

你可能感兴趣的:(反序列化多层嵌套json实体)