Object转实体对象

Object转实体对象

private  List convertOrgOrPerson(JSONObject jsonObject, Class valueType) throws Exception {
    JSONArray data = jsonObject.getJSONArray(RESULT_KEY);
    List list = new ArrayList<>();
    for (Object var : data) {
        T t = this.readValueMap(var, valueType);
        list.add(t);
    }
    return list;
}
/**
 * object转实体,属性相同
 */
private   T readValueMap(Object obj, Class valueType) throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    String str = null;
    try {
        str = objectMapper.writeValueAsString(obj);
        return (T) objectMapper.readValue(str, valueType);
    } catch (IOException e) {
        throw new Exception("实体转换异常,请维护!");
    }
}

你可能感兴趣的:(Object转实体对象)