title: XML Mapping of POJO to XML using jackson produces duplicate tags
body: <p><strong>Input Sample:</strong></p>
  
  <pre><code>{
    "InventoryDetails" : {
      "Inventory" : {
        "Details" : {
          "Category" : "Fruits",
          "Type" : "Perishable"
        },
        "Properties" : {
          "OptField" : [ {
            "Name" : "Apple",
            "Value" : "Red"
          }, {
            "Name" : "Orange",
            "Value" : "Orange"
          }, {
            "Name" : "Grapes",
            "Value" : "Green"
          }
      ]
        }
      }
    }
  }
  </code></pre>
  
  <p>I am mapping the json to pojo, and trying to convert the pojo to xml using xml mapper.</p>
  
  <p>There is a requirement for making this transformation, without converting json to xml directly, so I have to stick to it, as we have some transformation process before converting to xml</p>
  
  <p>But when i do that, I could see the root element tag is printed twice, Can someone help with me to fix this.</p>
  
  <p><strong>Output</strong></p>
  
  <pre><code>&lt;InventoryDetails&gt;
      &lt;InventoryDetails&gt;
          &lt;Inventory&gt;
              &lt;Details&gt;
                  &lt;Category&gt;Fruits&lt;/Category&gt;
                  &lt;Type&gt;Perishable&lt;/Type&gt;
              &lt;/Details&gt;
              &lt;Properties&gt;
                  &lt;OptField&gt;
                      &lt;Name&gt;Apple&lt;/Name&gt;
                      &lt;Value&gt;Red&lt;/Value&gt;
                  &lt;/OptField&gt;
                  &lt;OptField&gt;
                      &lt;Name&gt;Orange&lt;/Name&gt;
                      &lt;Value&gt;Orange&lt;/Value&gt;
                  &lt;/OptField&gt;
                  &lt;OptField&gt;
                      &lt;Name&gt;Grapes&lt;/Name&gt;
                      &lt;Value&gt;Green&lt;/Value&gt;
                  &lt;/OptField&gt;
              &lt;/Properties&gt;
          &lt;/Inventory&gt;
      &lt;/InventoryDetails&gt;
  &lt;/InventoryDetails&gt; 
  </code></pre>
  
  <p><strong>POJO 1</strong></p>
  
  <pre><code>package com.inventory;
  
  import java.util.HashMap;
  import java.util.Map;
  import javax.annotation.Generated;
  import com.fasterxml.jackson.annotation.JsonAnyGetter;
  import com.fasterxml.jackson.annotation.JsonAnySetter;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonInclude;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
  
  @JsonInclude(JsonInclude.Include.NON_NULL)
  @Generated("org.jsonschema2pojo")
  @JsonPropertyOrder({
      "Inventory"
  })
  public class InventoryDetails {
  
      @JsonProperty("Inventory")
      private com.inventory.Inventory Inventory;
      @JsonIgnore
      private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
      /**
       * 
       * @return
       *     The Inventory
       */
      @JsonProperty("Inventory")
      public com.inventory.Inventory getInventory() {
          return Inventory;
      }
  
      /**
       * 
       * @param Inventory
       *     The Inventory
       */
      @JsonProperty("Inventory")
      public void setInventory(com.inventory.Inventory Inventory) {
          this.Inventory = Inventory;
      }
  
      @JsonAnyGetter
      public Map&lt;String, Object&gt; getAdditionalProperties() {
          return this.additionalProperties;
      }
  
      @JsonAnySetter
      public void setAdditionalProperty(String name, Object value) {
          this.additionalProperties.put(name, value);
      }
  
  }
  </code></pre>
  
  <p><strong>POJO 2</strong></p>
  
  <pre><code>package com.inventory;
  
  import java.util.HashMap;
  import java.util.Map;
  import javax.annotation.Generated;
  import com.fasterxml.jackson.annotation.JsonAnyGetter;
  import com.fasterxml.jackson.annotation.JsonAnySetter;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonInclude;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
  
  @JsonInclude(JsonInclude.Include.NON_NULL)
  @Generated("org.jsonschema2pojo")
  @JsonPropertyOrder({
      "Details",
      "Properties"
  })
  public class Inventory {
  
      @JsonProperty("Details")
      private com.inventory.Details Details;
      @JsonProperty("Properties")
      private com.inventory.Properties Properties;
      @JsonIgnore
      private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
      /**
       * 
       * @return
       *     The Details
       */
      @JsonProperty("Details")
      public com.inventory.Details getDetails() {
          return Details;
      }
  
      /**
       * 
       * @param Details
       *     The Details
       */
      @JsonProperty("Details")
      public void setDetails(com.inventory.Details Details) {
          this.Details = Details;
      }
  
      /**
       * 
       * @return
       *     The Properties
       */
      @JsonProperty("Properties")
      public com.inventory.Properties getProperties() {
          return Properties;
      }
  
      /**
       * 
       * @param Properties
       *     The Properties
       */
      @JsonProperty("Properties")
      public void setProperties(com.inventory.Properties Properties) {
          this.Properties = Properties;
      }
  
      @JsonAnyGetter
      public Map&lt;String, Object&gt; getAdditionalProperties() {
          return this.additionalProperties;
      }
  
      @JsonAnySetter
      public void setAdditionalProperty(String name, Object value) {
          this.additionalProperties.put(name, value);
      }
  
  }
  </code></pre>
  
  <p><strong>POJO 3</strong></p>
  
  <pre><code>package com.inventory;
  
  import java.util.HashMap;
  import java.util.Map;
  import javax.annotation.Generated;
  import com.fasterxml.jackson.annotation.JsonAnyGetter;
  import com.fasterxml.jackson.annotation.JsonAnySetter;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonInclude;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
  
  @JsonInclude(JsonInclude.Include.NON_NULL)
  @Generated("org.jsonschema2pojo")
  @JsonPropertyOrder({
      "Category",
      "Type"
  })
  public class Details {
  
      @JsonProperty("Category")
      private String Category;
      @JsonProperty("Type")
      private String Type;
      @JsonIgnore
      private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
      /**
       * 
       * @return
       *     The Category
       */
      @JsonProperty("Category")
      public String getCategory() {
          return Category;
      }
  
      /**
       * 
       * @param Category
       *     The Category
       */
      @JsonProperty("Category")
      public void setCategory(String Category) {
          this.Category = Category;
      }
  
      /**
       * 
       * @return
       *     The Type
       */
      @JsonProperty("Type")
      public String getType() {
          return Type;
      }
  
      /**
       * 
       * @param Type
       *     The Type
       */
      @JsonProperty("Type")
      public void setType(String Type) {
          this.Type = Type;
      }
  
      @JsonAnyGetter
      public Map&lt;String, Object&gt; getAdditionalProperties() {
          return this.additionalProperties;
      }
  
      @JsonAnySetter
      public void setAdditionalProperty(String name, Object value) {
          this.additionalProperties.put(name, value);
      }
  
  }
  </code></pre>
  
  <p><strong>POJO 4</strong></p>
  
  <pre><code>package com.inventory;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import javax.annotation.Generated;
  import com.fasterxml.jackson.annotation.JsonAnyGetter;
  import com.fasterxml.jackson.annotation.JsonAnySetter;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonInclude;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
  
  @JsonInclude(JsonInclude.Include.NON_NULL)
  @Generated("org.jsonschema2pojo")
  @JsonPropertyOrder({
      "OptField"
  })
  public class Properties {
  
      @JsonProperty("OptField")
      private List&lt;com.inventory.OptField&gt; OptField = new ArrayList&lt;com.inventory.OptField&gt;();
      @JsonIgnore
      private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
      /**
       * 
       * @return
       *     The OptField
       */
      @JsonProperty("OptField")
      public List&lt;com.inventory.OptField&gt; getOptField() {
          return OptField;
      }
  
      /**
       * 
       * @param OptField
       *     The OptField
       */
      @JsonProperty("OptField")
      public void setOptField(List&lt;com.inventory.OptField&gt; OptField) {
          this.OptField = OptField;
      }
  
      @JsonAnyGetter
      public Map&lt;String, Object&gt; getAdditionalProperties() {
          return this.additionalProperties;
      }
  
      @JsonAnySetter
      public void setAdditionalProperty(String name, Object value) {
          this.additionalProperties.put(name, value);
      }
  
  }
  </code></pre>
  
  <p><strong>POJO 5</strong></p>
  
  <pre><code>package com.inventory;
  
  import java.util.HashMap;
  import java.util.Map;
  import javax.annotation.Generated;
  import com.fasterxml.jackson.annotation.JsonAnyGetter;
  import com.fasterxml.jackson.annotation.JsonAnySetter;
  import com.fasterxml.jackson.annotation.JsonIgnore;
  import com.fasterxml.jackson.annotation.JsonInclude;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.annotation.JsonPropertyOrder;
  
  @JsonInclude(JsonInclude.Include.NON_NULL)
  @Generated("org.jsonschema2pojo")
  @JsonPropertyOrder({
      "Name",
      "Value"
  })
  public class OptField {
  
      @JsonProperty("Name")
      private String Name;
      @JsonProperty("Value")
      private String Value;
      @JsonIgnore
      private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
      /**
       * 
       * @return
       *     The Name
       */
      @JsonProperty("Name")
      public String getName() {
          return Name;
      }
  
      /**
       * 
       * @param Name
       *     The Name
       */
      @JsonProperty("Name")
      public void setName(String Name) {
          this.Name = Name;
      }
  
      /**
       * 
       * @return
       *     The Value
       */
      @JsonProperty("Value")
      public String getValue() {
          return Value;
      }
  
      /**
       * 
       * @param Value
       *     The Value
       */
      @JsonProperty("Value")
      public void setValue(String Value) {
          this.Value = Value;
      }
  
      @JsonAnyGetter
      public Map&lt;String, Object&gt; getAdditionalProperties() {
          return this.additionalProperties;
      }
  
      @JsonAnySetter
      public void setAdditionalProperty(String name, Object value) {
          this.additionalProperties.put(name, value);
      }
  
  }
  </code></pre>
  
  <p><strong>Code TO Test</strong></p>
  
  <pre><code>package com.tester;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.InputStream;
  
  import org.apache.commons.io.IOUtils;
  
  import com.fasterxml.jackson.core.JsonProcessingException;
  import com.fasterxml.jackson.databind.ObjectMapper;
  import com.fasterxml.jackson.dataformat.xml.XmlMapper;
  import com.inventory.InventoryDetails;
  
  public class Tester {
  
      public static void main(String[] args) {
          String jsonStr = "";
          try (InputStream inputStream = new FileInputStream(
                  new File("file.json"))) {
              jsonStr = IOUtils.toString(inputStream);
          } catch (Exception e) {
              System.out.println(e.getMessage());
          }
  
          // Map to POJO
          ObjectMapper mapper = new ObjectMapper();
          InventoryDetails inventoryDetails = null;
          try {
              inventoryDetails = mapper
                      .readValue(jsonStr, InventoryDetails.class);
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          // Print XML
          ObjectMapper xmlMapper = new XmlMapper();
          String request = "";
          try {
              request = xmlMapper.writeValueAsString(inventoryDetails);
          } catch (JsonProcessingException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          System.out.println(request);
      }
  
  }
  </code></pre>