title: Jackson xml module: deserializing immutable type with a @JacksonXmlText property
body: <p>I want to serialize an immutable type both as json and as xml: </p>
  
  <p>The serialized JSON is like:</p>
  
  <pre class="lang-json prettyprint-override"><code>{
      "text" : "... the text..."
  }
  </code></pre>
  
  <p>and the serialized xml is like:</p>
  
  <pre class="lang-xml prettyprint-override"><code> &lt;asText&gt;_text_&lt;/asText&gt;
  </code></pre>
  
  <p><em>(note that the text is the xml's element text)</em></p>
  
  <p>The java object is like:</p>
  
  <pre class="lang-java prettyprint-override"><code>@JsonRootName("asText")
  @Accessors(prefix="_")
  public static class AsText {
  
      @JsonProperty("text") @JacksonXmlText
      @Getter private final String _text;
  
      public AsText(@JsonProperty("text") final String text) {
          _text = text;
      }
  }
  </code></pre>
  
  <p>beware that the _text property is <strong>final</strong> (so the object is immutable) and it's annotated with <code>@JacksonXmlText</code> in order to be serialized as the xml element's text</p>
  
  <p>Being the object immutable, a constructor from the text is needed and the constructor's argument must be annotated with <code>@JsonProperty</code></p>
  
  <pre class="lang-java prettyprint-override"><code>    public AsText(@JsonProperty("text") final String text) {
          _text = text;
      }
  </code></pre>
  
  <p>When serializing / deserializing to/from JSON everything works fine
  ... the problem arises when serializing / deserializing to/from XML:</p>
  
  <pre class="lang-java prettyprint-override"><code> // create the object
   AsText obj = new AsText("_text_");
  
   // init the mapper
   XmlMapper mapper = new XmlMapper();
  
   // write as xml
   String xml = mapper.writeValueAsString(obj);
   log.warn("Serialized Xml\n{}",xml);
  
   // Read from xml
   log.warn("Read from Xml:");
   AsText objReadedFromXml = mapper.readValue(xml,
                                                AsText.class);
   log.warn("Obj readed from serialized xml: {}",
            objReadedFromXml.getClass().getName());
  </code></pre>
  
  <p>The exception is:</p>
  
  <pre>
      com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "" (class r01f.types.url.UrlQueryStringParam), not marked as ignorable (2 known properties: "value", "name"])
  </pre>
  
  <p>It seems that the xml module needs the object's constructor to be annotated like: </p>
  
  <pre class="lang-java prettyprint-override"><code>    public AsText(@JsonProperty("") final String text) {
          _text = text;
      }
  </code></pre>
  
  <p>BUT this does NOT even works:</p>
  
  <pre>
      com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `test.types.SerializeAsXmlElementTextTest$AsText` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
  </pre>
  
  <p>The annotation <code>@JsonProperty("text")</code> at the constructor's argument is needed to deserialize from JSON</p>
  
  <p>... how can i make this to work</p>