@Data public class Entity { private String age; private String name; private String class; }
Entity entity = new Entity("20","灰太狼"); String jsonString = JSON.toJSONString(entity); JSONObject jsonObject = JSONObject.parseObject(jsonString); System.out.println(jsonObject);
-- 字段为NULL的则不会展示
{"age":"20","name":"灰太狼"}