0
帮忙看下泛型参数中的JSONField如何生效?
public static <T> RpcRespObj<T> convertResult(Class<T> type) {
String str = "{\"status\":0,\"data\":{\"resourceId\":2,\"resourceName\":\"own佛恩\",\"systemCode\":\"ad\"}}";
RpcRespObj<T> result = JSON.parseObject(str, new TypeReference<RpcRespObj<T>>(type) {});
return result;
}
public static void main(String[] args) {
RpcRespObj<Resource> resources = RbacController.convertResult(Resource.class);
System.out.println("value:" + resources);
}
public class RpcRespObj<T> {
private Integer status;
private Integer errcode;
private Integer errno;
private T data;
}
public class Resource {
@JSONField(name = "resource----id")
private Integer resourceId;
@JSONField(name = "resource----name")
private String resourceName;
private String systemCode;
}
运行结果:
value:RpcRespObj(status=0, errcode=null, errno=null, data=Resource(resourceId=2, resourceName=own佛恩, systemCode=ad))
可以看到 JSONField 重命名并没有生效