6

I get the following exception when i consume a restful webservice 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@2f2ddd7c; 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

The response parameter is

{

  "responseBaseParameters":  

{

  "responseCode": "32",

  "responseText": "Invalid Request",

  "incommTxnId": null,

  "IMP-SourceTxnId": "551932ba-6af4-44f9-ab98-db5bc96e962b"

 }

}

and my POJO class is

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 any insight as to why i am getting this error. Thanks

Costi Ciudatu
  • 37,042
  • 7
  • 56
  • 92
Ayodeji
  • 579
  • 2
  • 8
  • 25
  • Can you post the rest of the stack trace – Sotirios Delimanolis Jan 14 '14 at 22:21
  • What happens if you try to serialize your POJO to JSON? Does the serialized version have the field? – dimoniy Jan 14 '14 at 22:22
  • I haven't tried to serialize the same object because i don't have a need to. – Ayodeji Jan 14 '14 at 22:26
  • I think @dimoniy is suggesting you should try just to see what happens. – Vidya Jan 14 '14 at 22:31
  • When i serialize i got the following as output seBaseParameters": {"IMP-SourceTxnId":"abc123", "responseCode":"0", "responseText":"Success", "incommTxnId":"-4282972720901144148", "sourceTxnId":"abc123"}} – Ayodeji Jan 14 '14 at 22:39
  • 11
    Do you by any chance have two jackson libraries in your classpath (codehaus/jackson1 and fasterxml/jackson2) ? If so, you may have used the wrong annotation (actually the right annotation, but imported from the wrong package). – Costi Ciudatu Jan 14 '14 at 22:46
  • Yes i do but in a way. The codehaus/jackson1 is for another project which the second project uses. The second project has the fasterxml/jackson2 – Ayodeji Jan 14 '14 at 22:49
  • Can you check whether your IDE imported the right annotation as `JsonProperty` ? – Costi Ciudatu Jan 14 '14 at 22:50
  • This was the imported object org.codehaus.jackson.annotate.JsonProperty – Ayodeji Jan 14 '14 at 22:51
  • 9
    This seems to be it ! Just change that to the proper `com.fasterxml.jackson.annotation.JsonProperty` import and it should work. – Costi Ciudatu Jan 14 '14 at 23:04

0 Answers0