title: convert xml to Java object using jackson
body: <p>I want to convert XML to JSON using Jackson library. I have tried below code to get Json as below using jackson but I can't. if I tried using json, I can but I want to know how to do with Jackson library.</p>
  
  <pre><code>@RequestMapping(value="/convertXMLtoJson",method=RequestMethod.POST,consumes = MediaType.APPLICATION_XML_VALUE)
          public Map&lt;String,Object&gt; convertXMLtoJson(@RequestBody String strXMLData) {
              Map&lt;String,Object&gt; objresponseMessage = null;
              ObjectMapper objObjectMapper = new ObjectMapper();
              Employee objEmployee = null;
              try {
                  JSONObject obj = XML.toJSONObject(strXMLData);
                  ObjectMapper objectMapper = new XmlMapper();
                  objEmployee = objectMapper.readValue(strXMLData, Employee.class);
              objEmployeeService.save(objEmployee);
              } catch (Exception e) {
                  e.printStackTrace();
              }
              return objresponseMessage;
          }
  </code></pre>
  
  <p><strong>com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of <code>java.util.HashSet</code> out of VALUE_STRING token
   at [Source: (StringReader); line: 5, column: 15] (through reference chain: com.example.springboot.bean.Employee["Skills"])</strong></p>
  
  <pre><code>&lt;EmployeeDetail&gt;
     &lt;FirstName&gt;A&lt;/FirstName&gt;
     &lt;LastName&gt;Z&lt;/LastName&gt;
     &lt;Age&gt;20&lt;/Age&gt;
     &lt;Skills&gt;Java&lt;/Skills&gt;
     &lt;Skills&gt;J2EE&lt;/Skills&gt;
     &lt;Skills&gt;MSSQl&lt;/Skills&gt;
     &lt;Skills&gt;JAVA&lt;/Skills&gt;
     &lt;TotalExperience&gt;4&lt;/TotalExperience&gt;
     &lt;JobDetails&gt;
        &lt;CompanyName&gt;1&lt;/CompanyName&gt;
        &lt;Experience&gt;1.5&lt;/Experience&gt;
        &lt;Technologies&gt;Java&lt;/Technologies&gt;
        &lt;Technologies&gt;WebServices&lt;/Technologies&gt;
        &lt;Technologies&gt;MSSQL&lt;/Technologies&gt;
        &lt;Technologies&gt;J2EE&lt;/Technologies&gt;
        &lt;Location&gt;India&lt;/Location&gt;
     &lt;/JobDetails&gt;
     &lt;JobDetails&gt;
        &lt;CompanyName&gt;2&lt;/CompanyName&gt;
        &lt;Experience&gt;2.5&lt;/Experience&gt;
        &lt;Technologies&gt;Java&lt;/Technologies&gt;
        &lt;Technologies&gt;J2EE&lt;/Technologies&gt;
        &lt;Technologies&gt;MySQL&lt;/Technologies&gt;
        &lt;Technologies&gt;Spring&lt;/Technologies&gt;
        &lt;Location&gt;India&lt;/Location&gt;
     &lt;/JobDetails&gt;
  &lt;/EmployeeDetail&gt;
  </code></pre>
  
  <p>Expected Json as(Output Excepted)</p>
  
  <pre><code>{
      "EmployeeDetail": {
          "FirstName": "A",
          "LastName": "Z",
          "Age": "20",
          "Skills": [
              "Java",
              "J2EE",
              "MSSQl",
              "JAVA"
          ],
          "TotalExperience": "4",
          "JobDetails": [
              {
                  "CompanyName": "1",
                  "Experience": "1.5",
                  "Technologies": [
                      "Java",
                      "WebServices",
                      "MSSQL",
                      "J2EE"
                  ],
                  "Location": "India"
              },
              {
                  "CompanyName": "2",
                  "Experience": "2.5",
                  "Technologies": [
                      "Java",
                      "J2EE",
                      "MySQL",
                      "Spring"
                  ],
                  "Location": "India"
              }
          ]
      }
  }
  </code></pre>
  
  <p>Can Anyone help me to understand using Jackson library</p>
  
  <pre><code>import java.io.Serializable;
  import java.util.List;
  import java.util.Set;
  import org.springframework.data.annotation.Id;
  import org.springframework.data.mongodb.core.mapping.Document;
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
  
  @Document
  @JacksonXmlRootElement(localName="EmployeeDetail")
  public class Employee implements Serializable {
  
      @Id
      private String userId;
  
      @JacksonXmlProperty(localName="FirstName")
      @JsonProperty("FirstName")
      private String firstName;
  
      @JacksonXmlProperty(localName="LastName")
      @JsonProperty("LastName")
      private String lastName;
  
      @JacksonXmlProperty(localName="Age")
      @JsonProperty("Age")
      private Integer age;
  
      @JacksonXmlElementWrapper(localName="Skills")
      @JsonProperty("Skills")
      private Set&lt;String&gt; skills;
  
      @JacksonXmlProperty(localName="JobDetails")
      @JsonProperty("JobDetails")
      private List&lt;JobDetails&gt; jobDetails;
  
      public String getUserId() {
          return userId;
      }
  
      public void setUserId(String userId) {
          this.userId = userId;
      }
  
      public Integer getAge() {
          return age;
      }
  
      public void setAge(Integer age) {
          this.age = age;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public String getFirstName() {
          return firstName;
      }
  
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
  
      public List&lt;JobDetails&gt; getJobDetails() {
          return jobDetails;
      }
  
      public void setJobDetails(List&lt;JobDetails&gt; jobDetails) {
          this.jobDetails = jobDetails;
      }
  
      public Set&lt;String&gt; getSkills() {
          return skills;
      }
  
      public void setSkills(Set&lt;String&gt; skills) {
          this.skills = skills;
      }
  
  }
  
  import java.util.Set;    
  import com.fasterxml.jackson.annotation.JsonProperty;
  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
  
  @JacksonXmlRootElement(localName="JobDetails")
  public class JobDetails {
  
      JobDetails(String str) {
  
      }
  
      @JacksonXmlProperty(localName="CompanyName")
      @JsonProperty("CompanyName")
      private String companyName;
  
      @JacksonXmlProperty(localName="Experience")
      @JsonProperty("Experience")
      private Integer experience;
  
      @JacksonXmlProperty(localName="Location")
      @JsonProperty("Location")
      private String location;
  
      @JacksonXmlElementWrapper(localName="Technologies")
      @JsonProperty("Technologies")
      private Set&lt;String&gt; technologies;
  
      public String getCompanyName() {
          return companyName;
      }
  
      public void setCompanyName(String companyName) {
          this.companyName = companyName;
      }
  
      public Integer getExperience() {
          return experience;
      }
  
      public void setExperience(Integer experience) {
          this.experience = experience;
      }
  
      public String getLocation() {
          return location;
      }
  
      public void setLocation(String location) {
          this.location = location;
      }
  
      public Set&lt;String&gt; getTechnologies() {
          return technologies;
      }
  
      public void setTechnologies(Set&lt;String&gt; technologies) {
          this.technologies = technologies;
      }
  
  }
  </code></pre>