Jackson – Marshall XML to POJO Unrecognized field error

I have a response from a RESTful XML webservice, stored as a string.

String responseAsStr = response.readEntity(String.class);          

Im trying to map the response to an object I generated using a schema.

XmlMapper xmlMapper = new XmlMapper(); ResponseType responseAsObj = xmlMapper.readValue(responseAsStr, ResponseType.class); 

When executing the line xmlMapper.readValue(…) I get this error :

Unrecognized field "ResponseType" (class blah.bleh.smth.ResponseType), not marked as ignorable (22 known properties: "responseType" ...)  

The generated class containing the problem field looks like this:

@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = {     "responseType",     ... }) @XmlRootElement(name = "SomeClassElement") public class SomeClassElement {      @XmlElement(name = "ResponseType")     protected ResponseType responseType;      ...      public ResponseType getResponseType() {         return responseType;     }      public void setErrorDetail(ResponseType value) {         this.responseType = value;     }      ... } 

The problem field class looks like:

@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = {     "1",     "2" }) public static class ResponseType {      @XmlElement(name = "1", required = true)     protected String 1;     @XmlElement(name = "2", required = true)     protected String 2;      /** 

The incoming XML Looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <SomeClassElement xmlns="redacted">     <ResponseType>         <1>BlahBlah</1>         <2>BlahBlah</2>     </ResponseType> </SomeClassElement> 

Has anyone encountered this before? It seems as if Jackson is unable to identify the field due to the lack of capitalisation in the "known properties" array (responseType as opposed to ResponseType). I altered the @XmlType decorator to see if changing capitalization fixed the issue here but alas the error persists.

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.