title: Converting JSON to XML XmlMapper- Jackson 2.10
body: <p>I have pojos with @JsonProperties. I use these to read JSON and parse to POJO. I am now having to post these pojos formatted as XML. </p>
  
  <p>The Required XML format to successfully post looks like this (note the namespace type, xsi type formatting):</p>
  
  <pre><code>&lt;network_objects&gt;
      &lt;network_object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="subnetNetworkObjectDTO"&gt;
          &lt;name&gt;TestSubnet&lt;/name&gt;
          &lt;display_name&gt;TestSubnet&lt;/display_name&gt;
          &lt;global&gt;false&lt;/global&gt;
          &lt;application_id&gt;3&lt;/application_id&gt;
          &lt;type&gt;subnet&lt;/type&gt;
          &lt;ip&gt;5.207.206.0&lt;/ip&gt;
          &lt;netmask&gt;255.255.254.0&lt;/netmask&gt;
      &lt;/network_object&gt;
      &lt;network_object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="networkObjectGroupDTO"&gt;
          &lt;name&gt;Test01Subnets&lt;/name&gt;
          &lt;display_name&gt;Test01Subnets&lt;/display_name&gt;
          &lt;application_id&gt;3&lt;/application_id&gt;
          &lt;type&gt;group&lt;/type&gt;
      &lt;/network_object&gt;
  &lt;/network_objects&gt;
  </code></pre>
  
  <p>I pass the created Application Class (shown below) to convert to XML</p>
  
  <pre><code>    ObjectMapper mapper = new XmlMapper(); 
      mapper.enable(SerializationFeature.INDENT_OUTPUT);        
      byte[] val = mapper.writeValueAsBytes(myApp);
  </code></pre>
  
  <p>The output is a bit off and does not contain the xmlns and the xsi looks different. It also has 'Application' as root: </p>
  
  <pre><code>&lt;Application&gt;
   &lt;network_objects&gt;
    &lt;network_object&gt;
     &lt;network_object&gt;
      &lt;@xsi.type&gt;networkObjectGroupDTO&lt;/@xsi.type&gt;
      &lt;name&gt;name&lt;/name&gt;
      &lt;display_name&gt;displayName&lt;/display_name&gt;
      &lt;application_id&gt;3&lt;/application_id&gt;
      &lt;type&gt;group&lt;/type&gt;
     &lt;/network_object&gt;
    &lt;/network_object&gt;
   &lt;/network_objects&gt;
  &lt;/Application&gt;
  </code></pre>
  
  <p>When I output the class to JSON, it looks as expected (No "Application" as root). </p>
  
  <pre><code>    ObjectMapper mapper = new ObjectMapper();
      mapper.enable(SerializationFeature.INDENT_OUTPUT);        
      byte[] val = mapper.writeValueAsBytes(myApp);
  
  
  {
  "network_objects" : {
  "network_object" : [ {
    "@xsi.type" : "networkObjectGroupDTO",
    "name" : "name",
    "display_name" : "displayName",
    "application_id" : 3,
    "type" : "group"
     }
    }
  }
  </code></pre>
  
  <p>What do I need to modify with my XmlMapper() or POJOs in order to get the XML formatted correctly? </p>
  
  <p>Below are the POJOs used for this. </p>
  
  <p>Application Class:</p>
  
  <pre><code>@JsonInclude(JsonInclude.Include.NON_NULL)
  @JsonPropertyOrder({
  "network_objects"
  })
  public class Application {
  
  @JsonProperty("network_objects")
  private NetworkObjects networkObjects;
  @JsonIgnore
  private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
  @JsonProperty("network_objects")
  public NetworkObjects getNetworkObjects() {
      return networkObjects;
  }
  
  @JsonProperty("network_objects")
  public void setNetworkObjects(NetworkObjects networkObjects) {
      this.networkObjects = networkObjects;
  }
  
  @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>NetworkObjects Class:</p>
  
  <pre><code>@JsonInclude(JsonInclude.Include.NON_NULL)
   @JsonPropertyOrder({
  "network_object"
   })
   public class NetworkObjects {
  
  @JsonProperty("network_object")
  private List&lt;NetworkObject&gt; networkObject = null;
  @JsonIgnore
  private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
  @JsonProperty("network_object")
  public List&lt;NetworkObject&gt; getNetworkObject() {
      return networkObject;
  }
  
  @JsonProperty("network_object")
  public void setNetworkObject(List&lt;NetworkObject&gt; networkObject) {
      this.networkObject = networkObject;
  }
  
  @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>NetworkObject Class:</p>
  
  <pre><code>@JsonInclude(JsonInclude.Include.NON_NULL)
   @JsonPropertyOrder({
  "@xsi.type",
  "id",
  "uid",
  "name",
  "display_name",
  "global",
  "comment",
  "application_id",
  "type",
  "ip",
  "access_allowed",
  "member",
  "last_ip",
  "first_ip",
  "netmask"
   })
   public class NetworkObject {
  
  @JsonProperty("@xsi.type")
  private String xsiType;
  @JsonProperty("id")
  private Integer id;
  @JsonProperty("uid")
  private String uid;
  @JsonProperty("name")
  private String name;
  @JsonProperty("display_name")
  private String displayName;
  @JsonProperty("global")
  private Boolean global;
  @JsonProperty("comment")
  private String comment;
  @JsonProperty("application_id")
  private Integer applicationId;
  @JsonProperty("type")
  private String type;
  @JsonProperty("ip")
  private String ip;
  @JsonProperty("access_allowed")
  private Boolean accessAllowed;
  @JsonProperty("member")
  private List&lt;Member&gt; member = null;
  @JsonProperty("last_ip")
  private String lastIp;
  @JsonProperty("first_ip")
  private String firstIp;
  @JsonProperty("netmask")
  private String netmask;
  @JsonIgnore
  private Map&lt;String, Object&gt; additionalProperties = new HashMap&lt;String, Object&gt;();
  
  @JsonProperty("@xsi.type")
  public String getXsiType() {
      return xsiType;
  }
  
  @JsonProperty("@xsi.type")
  public void setXsiType(String xsiType) {
      this.xsiType = xsiType;
  }
  
  @JsonProperty("id")
  public Integer getId() {
      return id;
  }
  
  @JsonProperty("id")
  public void setId(Integer id) {
      this.id = id;
  }
  
  @JsonProperty("uid")
  public String getUid() {
      return uid;
  }
  
  @JsonProperty("uid")
  public void setUid(String uid) {
      this.uid = uid;
  }
  
  @JsonProperty("name")
  public String getName() {
      return name;
  }
  
  @JsonProperty("name")
  public void setName(String name) {
      this.name = name;
  }
  
  @JsonProperty("display_name")
  public String getDisplayName() {
      return displayName;
  }
  
  @JsonProperty("display_name")
  public void setDisplayName(String displayName) {
      this.displayName = displayName;
  }
  
  @JsonProperty("global")
  public Boolean getGlobal() {
      return global;
  }
  
  @JsonProperty("global")
  public void setGlobal(Boolean global) {
      this.global = global;
  }
  
  @JsonProperty("comment")
  public String getComment() {
      return comment;
  }
  
  @JsonProperty("comment")
  public void setComment(String comment) {
      this.comment = comment;
  }
  
  @JsonProperty("application_id")
  public Integer getApplicationId() {
      return applicationId;
  }
  
  @JsonProperty("application_id")
  public void setApplicationId(Integer applicationId) {
      this.applicationId = applicationId;
  }
  
  @JsonProperty("type")
  public String getType() {
      return type;
  }
  
  @JsonProperty("type")
  public void setType(String type) {
      this.type = type;
  }
  
  @JsonProperty("ip")
  public String getIp() {
      return ip;
  }
  
  @JsonProperty("ip")
  public void setIp(String ip) {
      this.ip = ip;
  }
  
  @JsonProperty("access_allowed")
  public Boolean getAccessAllowed() {
      return accessAllowed;
  }
  
  @JsonProperty("access_allowed")
  public void setAccessAllowed(Boolean accessAllowed) {
      this.accessAllowed = accessAllowed;
  }
  
  @JsonProperty("member")
  public List&lt;Member&gt; getMember() {
      return member;
  }
  
  @JsonProperty("member")
  public void setMember(List&lt;Member&gt; member) {
      this.member = member;
  }
  
  @JsonProperty("last_ip")
  public String getLastIp() {
      return lastIp;
  }
  
  @JsonProperty("last_ip")
  public void setLastIp(String lastIp) {
      this.lastIp = lastIp;
  }
  
  @JsonProperty("first_ip")
  public String getFirstIp() {
      return firstIp;
  }
  
  @JsonProperty("first_ip")
  public void setFirstIp(String firstIp) {
      this.firstIp = firstIp;
  }
  
  @JsonProperty("netmask")
  public String getNetmask() {
      return netmask;
  }
  
  @JsonProperty("netmask")
  public void setNetmask(String netmask) {
      this.netmask = netmask;
  }
  
  @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>