title: Parse XML to Object Java
body: <p>I Have a this <strong>xml</strong>:</p>
  
  <pre><code>&lt;Link ID="6" Name="ALM_JIRA_BUG_2POSICIONGL"&gt;
   &lt;Endpoint ordinal="1"&gt;
              &lt;type&gt;Micro-Focus-ALM&lt;/type&gt;
              &lt;epName&gt;Micro-Focus-ALM&lt;/epName&gt;
              &lt;entityName&gt;Defect&lt;/entityName&gt;
              &lt;entityType&gt;DEFECT&lt;/entityType&gt;
              &lt;ConnectionData&gt;
                  &lt;username&gt;sa_aplservmercury&lt;/username&gt;
                  &lt;password encryptInitString="p2yY5PjzSJs/pn5Kmzz/TQ=="
                      encrypted="true" value="Iwxz/rPt9elfoFxWSqnvfw=="/&gt;
          &lt;Properties&gt;
                      &lt;property name="ServerURL" value="http://alm3.produban.gs.corp/qcbin"/&gt;
                      &lt;property name="Domain" value="QAF_SAN_AGILE"/&gt;
                      &lt;property name="Project" value="PG_ADN360"/&gt;
                  &lt;/Properties&gt;
  
              &lt;/ConnectionData&gt;
  
              &lt;/Filters&gt;
              &lt;Params/&gt;
          &lt;/Endpoint&gt;
  &lt;/Link&gt;
  </code></pre>
  
  <p>And these parsing classes</p>
  
  <pre><code>@Data
  public class PropertyXml {
  
      @JacksonXmlProperty(isAttribute = false, localName = "property")
      private String property;
  
      @JacksonXmlProperty(isAttribute = true, localName = "name")
      private String name;
  
      @JacksonXmlProperty(isAttribute = true, localName = "value")
      private String value;
  
  }
  
  @Data
  @AllArgsConstructor
  @NoArgsConstructor
  public class Properties {
  
      @JacksonXmlProperty(isAttribute = false, localName = "Properties")
      @JacksonXmlElementWrapper(useWrapping = false)
      List&lt;PropertyXml&gt; properties = new ArrayList&lt;&gt;();
  }
  
  @JacksonXmlRootElement(localName = "ConnectionData")
  public class ConnectionData {
  
      @JacksonXmlProperty(localName = "username")
      private String userName;
  
      @JacksonXmlProperty(localName = "password")
      private Password password;
  
      @JacksonXmlProperty(localName = "Properties")
      private Properties properties;
  
  }
  
  @JacksonXmlRootElement(localName = "ConnectionData")
  public class ConnectionData {
  
      @JacksonXmlProperty(localName = "username")
      private String userName;
  
      @JacksonXmlProperty(localName = "password")
      private Password password;
  
      @JacksonXmlProperty(localName = "Properties")
      private Properties properties;
  
  }
  
  
  public class Endpoint {
  
      @JacksonXmlProperty(isAttribute = true, localName = "ordinal")
      private String ordinal;
  
      @JacksonXmlProperty(isAttribute = false, localName = "type")
      private String type;
  
      @JacksonXmlProperty(isAttribute = false, localName = "epName")
      private String epName;
  
      @JacksonXmlProperty(isAttribute = false, localName = "entityName")
      private String entityName;
  
      @JacksonXmlProperty(isAttribute = false, localName = "entityType")
      private String entityType;
  
      @JacksonXmlProperty(isAttribute = false, localName = "ConnectionData")
      private ConnectionData connectionData;
  
      @JacksonXmlProperty(isAttribute = false, localName = "Filters")
      private String filters;
  
      @JacksonXmlProperty(isAttribute = false, localName = "Params")
      private String params;
  
  }
  
  public class Link {
  
      @JacksonXmlProperty(isAttribute = true, localName = "ID")
      private String id;
  
      @JacksonXmlProperty(isAttribute = true, localName = "Name")
      private String name;
  
      @JacksonXmlProperty(isAttribute = false, localName = "Endpoint")
      private Endpoint endpoint;
  }
  
  A través de este código leo el fichero y hago la deserialización:
  </code></pre>
  
  <p>Service Class:</p>
  
  <pre><code>@Service
  public class ConvertToXmlJsonImpl implements ConvertToXmlJsonService {
  
      public void convertFromXmlFile() {
          File file = new File("C:/incremental.xml");
          XmlMapper xmlMapper = new XmlMapper();
          Link value = null;
          //ConvertToXmlJsonModel value = null;
          String xml = null;
          try {
              xml = inputStreamToString(new FileInputStream(file));
              //value = xmlMapper.readValue(xml, ConvertToXmlJsonModel.class);
              value = xmlMapper.readValue(xml, Link.class);
              System.out.print(value);
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          //return value;
      }
  
      private String inputStreamToString(FileInputStream fileInputStream) throws IOException {
  
          StringBuilder sb = new StringBuilder();
          String line;
          BufferedReader br = new BufferedReader(new InputStreamReader(fileInputStream));
          while ((line = br.readLine()) != null) {
              sb.append(line);
          }
          br.close();
          return sb.toString();
      }
  </code></pre>
  
  <p>when making the mapper returns an <strong>exception</strong> :</p>
  
  <blockquote>
    <p>com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
    Unrecognized field "name" (class
    com.example.convertToXmlJson.model.Properties), not marked as
    ignorable (one known property: "Properties"])  at [Source:
    (StringReader); line: 1, column: 567] (through reference chain:
    com.example.convertToXmlJson.model.Link["Endpoint"]->com.example.convertToXmlJson.model.Endpoint["ConnectionData"]->com.example.convertToXmlJson.model.ConnectionData["Properties"]->java.util.ArrayList[0]->com.example.convertToXmlJson.model.Properties["name"])</p>
  </blockquote>