简体   繁体   English

无法读取 JSON:属性的设置器定义冲突

[英]Could not read JSON: Conflicting setter definitions for property

When I call the API for the first time, I receive a JSON response without any error.当我第一次调用 API 时,我收到 JSON 响应,没有任何错误。

When I call the API for the second time, I receive:当我第二次调用 API 时,我收到:

 Could not read JSON: Conflicting setter definitions for property "zipCode": com.sfr.cacheaddress.api.model.Address#setZipCode(1 params) vs com.sfr.cacheaddress.api.model.Address#setZipCode(1 params) at [Source: (byte[])"{"@class":"com.sfr.cacheaddress.api.model.MetaAddress","address":{"id":"3525622624","streetNumber":5,"streetNumberComplement":"A","streetType":"RUE","streetName":"RUE DES PERRIERES","streetNumberAndName":"5 A RUE DES PERRIERES","zipCode":"35800","city":"ST BRIAC SUR MER","address":"5 A RUE DES PERRIERES, 35800 ST BRIAC SUR MER","inseeCode":"35256","enabled":false,"codeRivoli":"0611","matriculeVoie":"00676767"},"complementCount":1}"; line: 1, column: 11 ]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Conflicting setter definitions for property "zipCode": com.sfr.cacheaddress.api.model.Address#setZipCode(1 params) vs com.sfr.cacheaddress.api.model.Address#setZipCode(1 params) at [Source: (byte[])"{"@class":"com.sfr.cacheaddress.api.model.MetaAddress","address":{"id":"3525622624","streetNumber":5,"streetNumberComplement":"A","streetType":"RUE","streetName":"RUE DES PERRIERES","streetNumberAndName":"5 A RUE DES PERRIERES","zipCode":"35800","city":"ST BRIAC SUR MER","address":"5 A RUE DES PERRIERES, 35800 ST BRIAC SUR MER","inseeCode":"35256","enabled":false,"codeRivoli":"0611","matriculeVoie":"00676767"},"complementCount":1}"; line: 1, column: 11

The Get API:获取 API:

 @GetMapping("streetNumber") public MetaAddress getAddressByIdRivoliStreetNumber(String code) { return addressService.findByRivoliStreetNumber(code); }

MetaAddress.java:元地址.java:

 @Data @NoArgsConstructor @JsonIgnoreProperties(ignoreUnknown = true) public class MetaAddress { Address address; long complementCount; }

Address.java:地址.java:

 @Data @NoArgsConstructor @JsonIgnoreProperties(ignoreUnknown = true) public final class Address implements Serializable { private String id; private String zipCode; private String city; //@JsonIgnore public void setZipCode(String zipCode) { this.zipCode = zipCode; } @JsonSetter public void setZipCode(String[] zipCode) { this.zipCode = zipCode[0]; } }

During deserializing, the second setZipCode(String[] zipCode) is needed (which contains @JsonSetter ), I tried to add @JsonIgnore to first method public void setZipCode(String zipCode) but the issue persists.在反序列化期间,需要第二个setZipCode(String[] zipCode) (其中包含@JsonSetter ),我尝试将@JsonIgnore添加到第一个方法public void setZipCode(String zipCode)但问题仍然存在。

Precision: Other APIs which use Adress class (not MetaAddres ) work fine.精度:使用Adress class (不是MetaAddres )的其他 API 工作正常。 The issue happens just when I call the API that uses MetaAddress object问题发生在我调用使用MetaAddress object 的 API

Anyone encountered the same problem please?请问有人遇到同样的问题吗?

One solution is to remove the cache.一种解决方案是删除缓存。 Another better solution is to remove the conflicting setter by removing one of them or removing both as you are already using @Data annotation.另一个更好的解决方案是通过删除其中一个或同时删除两个设置器来删除冲突的设置器,因为您已经在使用@Data注释。

If you expect different zipCode formats from the json returned by addressService.findByRivoliStreetNumber(code) such as string and array of strings, then you can deal with both formates as different properties.如果您期望与addressService.findByRivoliStreetNumber(code)返回的 json 不同的邮政编码格式,例如 string 和字符串数组,那么您可以将两种甲酸盐作为不同的属性处理。

If you have a special reason to do this, please mention it.如果您有特殊原因这样做,请提及。 Maybe there is a better design handing of this case.也许这种情况下有更好的设计处理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 属性“ thenComparing”的setter定义冲突: - Conflicting setter definitions for property “thenComparing”: Kotlin-无法编写JSON:属性的getter定义冲突(HttpMessageNotWritableException) - Kotlin - Could not write JSON: Conflicting getter definitions for property (HttpMessageNotWritableException) 与 iText7 一起使用时属性的 setter 定义冲突 - Conflicting setter definitions for property when using with iText7 org.codehaus.jackson.map.JsonMappingException:属性“ matchColumn”的设置器定义冲突:com.sun.rowset.JdbcRowSetImpl - org.codehaus.jackson.map.JsonMappingException: Conflicting setter definitions for property “matchColumn”: com.sun.rowset.JdbcRowSetImpl Jackson ObjectMapper冲突的setter定义(Android.Graphics.Bitmap) - Jackson ObjectMapper Conflicting setter definitions (Android.Graphics.Bitmap) Lombok 和 jackson - 冲突/不明确的属性名称定义 - Lombok and jackson - Conflicting/ambiguous property name definitions 如何在不访问源代码的情况下解决 jackson 中属性的冲突 getter 定义 - How to solve conflicting getter definitions for property in jackson without access to source 使用Jackson 2.9.6的运动衫中的属性名称定义冲突 - Conflicting property name definitions in jersey ,using Jackson 2.9.6 Jackson mapper 在三星 SM-T580 上抛出“冲突的 setter 定义” - Jackson mapper throws “conflicting setter definitions” on Samsung SM-T580 找不到属性设置器方法setAlpha - Could not find property setter method setAlpha
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM