目录
- 1、Object转List对象
- 2、Object转实体对象
1、Object转List对象
List<User> userList= MtUtils.ObjectToList(objData, User.class);
public static <T> List<T> ObjectToList(Object object, Class<T> clazz){try {List<T> result = new ArrayList<>();if (object instanceof List<?>){for (Object o : (List<?>) object) {String string = JSONObject.toJSONString(o);T t = JSONObject.parseObject(string, clazz);result.add(t);}return result;}return null;}catch (Exception e){e.printStackTrace();System.out.println(e.getMessage());}return null;
}
2、Object转实体对象
User user = JSONObject.parseObject(JSONObject.toJSONString(obj), User.class);