ResponseConvert.java 1.15 KB
package cn.com.glsx.entmicro.converter;

import cn.com.glsx.entmicro.model.worktool.BasePageResponse;
import cn.com.glsx.outbound.model.response.BaseResponse;
import com.alibaba.fastjson.JSONObject;

public class ResponseConvert {

    public static <T> BaseResponse<T> convertResponse(String json, Class<T> tClass) {
        BaseResponse<T> qcCodeResponse = JSONObject.parseObject(json, BaseResponse.class);
        String JSONStr = JSONObject.toJSONString(qcCodeResponse.getData());
        qcCodeResponse.setData(JSONObject.parseObject(JSONStr, tClass));
        return qcCodeResponse;
    }

    public static <T> BaseResponse<BasePageResponse<T>> convertPageResponse(String json, Class tClass) {
        BaseResponse qcCodeResponse = JSONObject.parseObject(json, BaseResponse.class);
        String JSONStr = JSONObject.toJSONString(qcCodeResponse.getData());
        BasePageResponse basePageResponse = JSONObject.parseObject(JSONStr, BasePageResponse.class);
        String list = basePageResponse.getList();
        basePageResponse.setListData(JSONObject.parseArray(list, tClass));
        qcCodeResponse.setData(basePageResponse);
        return qcCodeResponse;
    }
}