@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE)
该注解的作用是:使用属性名称来转json。 防止不规范的属性报错,比如 app_id
 
@JsonIgnoreProperties(ignoreUnknown = true)
该注解的作用是:在进行json转对象是,防止传入的json串包含不存在的属性导致报错。


案例:


1
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE) 2 @JsonIgnoreProperties(ignoreUnknown = true) 3 public class UnifiedPayOrderResponse { 4 5 private String code; 6 7 private String message; 8 9 private String main_order_code; 10 11 private String app_id; 12 13 public String getCode() { 14 return code; 15 } 16 17 public void setCode(String code) { 18 this.code = code; 19 } 20 21 public String getMessage() { 22 return message; 23 } 24 25 public void setMessage(String message) { 26 this.message = message; 27 } 28 29 public String getMain_order_code() { 30 return main_order_code; 31 } 32 33 public void setMain_order_code(String main_order_code) { 34 this.main_order_code = main_order_code; 35 } 36 37 public String getApp_id() { 38 return app_id; 39 } 40 41 public void setApp_id(String app_id) { 42 this.app_id = app_id; 43 } 44 45 }

 

posted on 2018-02-09 09:53  花开浪漫拾  阅读(5661)  评论(0编辑  收藏  举报