title: jackson xml deserialize inline array
body: <p>How to deserialize such strange XML. In my opinion, the props-entity is missing (around the props), but I can't change the source of this XML (a web service).</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;parents&gt;
    &lt;parent name="first"&gt;
      &lt;description&gt;&lt;![CDATA[Description for the first-Entity]]&gt;&lt;/description&gt;
      &lt;prop name="level"&gt;
        &lt;value&gt;&lt;![CDATA[1]]&gt;&lt;/value&gt;
      &lt;/prop&gt;
      &lt;prop name="enabled"&gt;
        &lt;value&gt;&lt;![CDATA[true]]&gt;&lt;/value&gt;
      &lt;/prop&gt;
      &lt;prop name="version"&gt;
        &lt;value&gt;&lt;![CDATA[1.0-beta3]]&gt;&lt;/value&gt;
      &lt;/prop&gt;
    &lt;/parent&gt;
    &lt;parent name="second"&gt;...&lt;/parent&gt;
    ...
  &lt;/parents&gt;
  </code></pre>
  
  <p>My entities are </p>
  
  <pre class="lang-java prettyprint-override"><code>public class Test {
      @Test
      public void deserializerTest() throws JsonParseException, JsonMappingException, IOException {
          ObjectMapper om = new XmlMapper();
          List&lt;Parent&gt; xml = om.readValue(new File("./test.xml"),
              new TypeReference&lt;List&lt;Parent&gt;&gt;() {});
      }
  }
  
  public class Prop {
      @JacksonXmlProperty(isAttribute = true)
      public String name;
  
      @JacksonXmlText
      public String value;
  }
  
  @JacksonXmlRootElement
  public class Parent {
      @JacksonXmlProperty(isAttribute = true)
      public String name;
  
      public String description;
  
      // 1. alternative with List
      public List&lt;Prop&gt; prop;
  
      // 2. alternative with Map
      @JsonDeserialize(using = PropDeser.class)
      public Map&lt;String, String&gt; prop;
  } 
  
  
  public static class PropDeser extends JsonDeserializer&lt;Map&lt;String, String&gt;&gt; {
  
      @Override
      public Map&lt;String, String&gt; deserialize(JsonParser jp,
              DeserializationContext ctxt) throws IOException,
              JsonProcessingException {
          Map&lt;String, String&gt; ret = new HashMap&lt;String, String&gt;();
          boolean eof = false;
          while (jp.hasCurrentToken()) {
              JsonToken t = jp.getCurrentToken();
              switch (t) {
              case END_OBJECT:
                  if (eof) {
                      return ret;
                  }
                  eof = true;
                  break;
              case VALUE_STRING:
                  ret.put(jp.getCurrentName(), jp.getText());
                  break;
              default:
                  eof = false;
                  break;
              }
              jp.nextValue();
          }
          return null;
      }
  
  }
  </code></pre>
  
  <h2>1. Alternative</h2>
  
  <p>creates an exception 'Can not instantiate value of type [simple type, class my.test.Prop] from JSON String; no single-String constructor/factory method (through reference chain: my.test.Parent["prop"])'</p>
  
  <p>I don't want a simple-String list. I need both: name and value. So I came to the idea of using a <code>Map&lt;String, String&gt;</code> by creating my own deserializer...</p>
  
  <h2>2. Alternative</h2>
  
  <p>The error seems to be method PropDeser.deserialize() consumes the closing-tag of the parent. </p>
  
  <pre><code>java.lang.NullPointerException
  at com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap.find(BeanPropertyMap.java:160)
  at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:287)
  at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:112)
  at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:226)
  at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:203)
  at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:23)
  at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2575)
  at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1766)
  at my.test.Test.deserializerTest(Test.java:57)
  </code></pre>
  
  <p>Is there a possibility to iterate backward in the <em>XML-stream</em>? How can the method know when to stop? I have no clue.</p>