<dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.3</version>
        </dependency>
 

 
public static void main(String[] args) throws Exception{
        JSONObject jo  = new JSONObject();
        jo.put("Test", "aaa");
        jo.put("Date", "2020-01-15");
        String json = jo.toJSONString();
        ObjectMapper gson = new ObjectMapper();
         // 转换为格式化的json
        gson.enable(SerializationFeature.INDENT_OUTPUT);
        // 如果json中有新增的字段并且是实体类类中不存在的,不报错
        gson.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        Aa aa= new ObjectMapper().readValue(json, Aa.class);
        System.out.println(aa);
        System.out.println(new ObjectMapper().writeValueAsString(aa));
    }
        public static class Aa{
            @JsonProperty("Test")
            private String test;
            @JsonProperty("Date")
            private String date;
             @JsonIgnore
            public String getTest() {
                return test;
            }

            public void setTest(String test) {
                this.test = test;
            }
             @JsonIgnore
            public String getDate() {
                return date;
            }

            public void setDate(String date) {
                this.date = date;
            }
        }

 


相关文章:

  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2018-08-14
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-02-16
  • 2022-12-23
  • 2021-04-05
  • 2021-10-19
相关资源
相似解决方案