title: "Unrecognized field (..), not marked as ignorable" while jaxb unmarshalling xml input
body: <p>in a typical Spring MVC project, I am trying to access objects that are fetched from an external webservice source. The actual integration of this data wasn't actually - until now - my part within the project. But it's broke and I'll have to fix it. That is to say: I am not perfectly familar with the related code.</p>
  
  <h1>Backgrounds</h1>
  
  <h2>The Data</h2>
  
  <p>The XML Data, which is received from the external web service looks like this:</p>
  
  <pre><code>&lt;offeredServiceTOes&gt;
     &lt;OfferedService deleted="false"&gt;
        &lt;id&gt;0001_01-u001/igd&lt;/id&gt;
        &lt;title&gt;Umschlagleistung (001)&lt;/title&gt;
        &lt;mainType&gt;turnover&lt;/mainType&gt;
        &lt;services&gt;
           &lt;service id="tos5yyeivg"&gt;
              &lt;title&gt;Umschlag Bahn - Binnenschiff&lt;/title&gt;
              &lt;mainType&gt;turnover&lt;/mainType&gt;
              &lt;systemId&gt;RailRiver&lt;/systemId&gt;
              &lt;meansOfTransport id="motRail"&gt;
                 &lt;title&gt;Bahn&lt;/title&gt;
                 &lt;description&gt;Bahn&lt;/description&gt;
                 &lt;systemId&gt;Rail&lt;/systemId&gt;
              &lt;/meansOfTransport&gt;
              &lt;meansOfTransportRel id="motRiver"&gt;
                 &lt;title&gt;Binnenschiff&lt;/title&gt;
                 &lt;description&gt;Binnenschiff&lt;/description&gt;
                 &lt;systemId&gt;River&lt;/systemId&gt;
              &lt;/meansOfTransportRel&gt;
           &lt;/service&gt;
           &lt;service id="tos5yyeiw0"&gt;
              [...]
           &lt;/service&gt;
           [...]
        &lt;/services&gt;
        [...]
      &lt;/OfferedService&gt;
      [...]
  &lt;offeredServiceTOes&gt;
  </code></pre>
  
  <h2>The Unmarshalling</h2>
  
  <ul>
  <li><p>The Method using Spring Rest Templates looks like this:</p>
  
  <pre><code>@Override
  public List&lt;OfferedServiceTO&gt; getOfferedServices() {
      return restTemplate.getForObject(
              dataServiceUriTemplate, 
              OfferedServiceTOList.class,
              OFFERED_SERVICES
      );
  </code></pre></li>
  <li><p>The related <code>OfferedServiceTOList</code> class:</p>
  
  <pre><code>@XmlRootElement(name="OfferedService")
  public class OfferedServiceTO
  {
  
      @XmlElement
      @XmlID
      public String id;
  
      // [...]
  
      @XmlElementWrapper(name="services")
      @XmlElement(name="service")
      public List&lt;ServiceTO&gt; services; 
  
      // [...]
  }
  </code></pre></li>
  <li><p>The related <code>ServiceTO</code> Class</p>
  
  <pre><code>@XmlRootElement(name="service")
  public class ServiceTO
  {
      // [...]
      @XmlElement
      public String title;
  
      /[...]
      @XmlElementWrapper(name="mainServices")
      @XmlElement(name="service")
      public List&lt;ServiceTO&gt; mainServices;
  }
  </code></pre></li>
  <li><p>The marshaller/unmarshaller xml bean configuration</p>
  
  <pre><code>&lt;bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
      &lt;property name="classesToBeBound"&gt;
          &lt;list&gt;
              &lt;value&gt;a.b.beans.ServiceTO&lt;/value&gt;
              &lt;value&gt;a.b.OfferedServiceTO&lt;/value&gt;
              [...]
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="xmlMessageConverter"
      class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt;
      &lt;constructor-arg ref="jaxbMarshaller" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jsonHttpMessageConverter"
      class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;
      &lt;property name="objectMapper" ref="jaxbJacksonObjectMapper"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jaxbJacksonObjectMapper"
      class="a.b.path.to.extended.jaxb.JaxbJacksonObjectMapper"&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"&gt;
      &lt;property name="objectMapper" ref="jaxbJacksonObjectMapper" /&gt;
  &lt;/bean&gt;
  </code></pre></li>
  <li><p>And finally, the above mentioned <code>path.to.extended.jaxb.JaxbJacksonObjectMapper</code>is:</p>
  
  <pre><code>    public class JaxbJacksonObjectMapper extends ObjectMapper {
  
          public JaxbJacksonObjectMapper() {
              final AnnotationIntrospector primary = new JaxbAnnotationIntrospector();
              final AnnotationIntrospector secondary = new JacksonAnnotationIntrospector();
              AnnotationIntrospector introspector = new AnnotationIntrospector.Pair(primary, secondary);
              DeserializationConfig deserializationConfig = super.getDeserializationConfig().withAnnotationIntrospector(introspector);
              DeserializationProblemHandler errorHandler = new DeserializationProblemHandler() {
                  @Override
                  public boolean handleUnknownProperty(DeserializationContext ctxt, JsonDeserializer&lt;?&gt; deserializer, Object beanOrClass,
                          String propertyName) throws IOException, JsonProcessingException {
                      //TODO Logging (unbekanntes Input-JSON)
                      ctxt.getParser().skipChildren();
                      return true;
                  }
              };
              deserializationConfig.addHandler(errorHandler );
              super.setDeserializationConfig(deserializationConfig);
              SerializationConfig serializationConfig = super.getSerializationConfig().withAnnotationIntrospector(introspector);
              serializationConfig.set(Feature.WRAP_ROOT_VALUE, true);
              super.setSerializationConfig(serializationConfig);
          }
  
      }
  </code></pre></li>
  </ul>
  
  <h1>The Problem</h1>
  
  <p>The problem is, that the Annotations of the first listing, <code>@XmlElementWrapper(name="services") @XmlElement(name="service")</code>, look fine to me regarding the xml data wrapping. But I keep getting the error:</p>
  
  <pre><code>[...] nested exception is org.springframework.web.client.ResourceAccessException: I/O error: Unrecognized field "service" (Class a.b.ServiceTO), not marked as ignorable
   at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@76d697d9; line: 7, column: 18] (through reference chain: a.b.OfferedServiceTO["services"]-&gt;a.b.ServiceTO["service"]); nested exception is org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "service" (Class a.b.ServiceTO), not marked as ignorable
   at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@76d697d9; line: 7, column: 18] (through reference chain: a.b.OfferedServiceTO["services"]-&gt;a.b.ServiceTO["service"])
      at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
  </code></pre>
  
  <p>Similar related questions like <a href="https://stackoverflow.com/questions/5325362/jaxb-unmarshalling-multiple-xml-elements-into-single-class">this one</a> were fixed by annotating <code>@XmlElementWrapper(name="services")</code>. But this is already present.</p>
  
  <p>I would appreciate any suggestions. Thank you. </p>
  
  <p>-- Martin</p>