@JsonProperty is not working properly

I get the following exception when I consume a calm web service using Spring RestTemplate

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "IMP-SourceTxnId" (class com.model.ResponseBaseParameters) not marked as ignorable (4 known properties: , "sourceTxnId", "incommTxnId", "responseCode", "responseText"]) at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@2f2d dd7c; line: 1, column: 130] (through reference chain: com.incomm.ife.model.rogers.RogersTransactionResponse["responseBaseParameters"]->com.incomm.ife.model.rogers.ResponseBaseParameters["IMP-SourceTxnId"]) at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:79) at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:555) at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:708) at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1159) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:315) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121) at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:449) at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:98) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2094) at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readInternal(MappingJackson2HttpMessageConverter.java:123) ... 54 more 

Response parameter

 { "responseBaseParameters": { "responseCode": "32", "responseText": "Invalid Request", "incommTxnId": null, "IMP-SourceTxnId": "551932ba-6af4-44f9-ab98-db5bc96e962b" } } 

and my pojo class

 public class ResponseBaseParameters { private String responseCode; private String responseText; private String incommTxnId; @JsonProperty("IMP-SourceTxnId") private String sourceTxnId; public String getResponseCode() { return responseCode; } public void setResponseCode(String responseCode) { this.responseCode = responseCode; } public String getResponseText() { return responseText; } public void setResponseText(String responseText) { this.responseText = responseText; } public String getIncommTxnId() { return incommTxnId; } public void setIncommTxnId(String incommTxnId) { this.incommTxnId = incommTxnId; } public String getSourceTxnId() { return sourceTxnId; } public void setSourceTxnId(String sourceTxnId) { this.sourceTxnId = sourceTxnId; } } 

Please make it clear why I get this error. Thanks

+1
source share
1 answer

There are many REST API implementations, and they conflict with each other. After a while, I solved this configuration:

 import com.fasterxml.jackson.annotation.JsonProperty; ... @JsonProperty("cep") private String cep; 

Must have this JsonProperty with this package not org.codehaus ...

 <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> <version>1.19</version> <scope>test</scope> </dependency> 

In conclusion: jersey client 1, property jackson json and remove all other jaxrc libs .

Obs :. I used jackson because the container is already provided, but if it works for you, you can test other combinations.

+1
source

Source: https://habr.com/ru/post/1232528/


All Articles