I have a XML file which i want to deserialize using Jackson.But i am getting the above Exception.
<students>
<student>
<Name>Tapishnu2</Name>
<Age>25</Age>
<Department>Computer</Department>
</student>
<student>
<Name>Tapishnu1</Name>
<Age>25</Age>
<Department>Computer</Department>
</student>
<student>
<Name>Tapishnu2</Name>
<Age>25</Age>
<Department>Computer</Department>
</student>
<student>
<Name>Tapishnu3</Name>
<Age>25</Age>
<Department>Computer</Department>
</student>
</students>
I have a POJO class like this
@JacksonXmlRootElement(localName = "students")
public class Students {
@JacksonXmlProperty(localName = "student")
private Student[] student;
/*public Students(){
}*/
public Students( Student[] student) {
super();
this.student = student;
}
public Student[] getStudent() {
return student;
}
public void setStudent(Student[] student) {
this.student = student;
}
@Override
public String toString() {
return "students [student=" + Arrays.toString(student) + "]";
}
}
public class Student {
@JacksonXmlProperty(localName = "Name")
String Name;
@JacksonXmlProperty(localName = "Age")
String Age;
@JacksonXmlProperty(localName = "Department")
String Department;
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
public String getAge() {
return Age;
}
public void setAge(String Age) {
this.Age = Age;
}
public String getDepartment() {
return Department;
}
public void setDepartment(String department) {
Department = department;
}
@Override
public String toString() {
return "Student [Name=" + Name + ", Age=" + Age + ", Department="
+ Department + "]";
}
}
Main class
file = new File("C://Avatar//Students.xml");
System.out.println(file.canRead());
XmlMapper mapper = new XmlMapper();
Students openCredentials = mapper.readValue(file, Students.class);
I am getting the following Error com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class com.Team.Students]: can not instantiate from JSON object (missing default constructor or creator, or perhaps need to add/enable type information?) at [Source: C:\Avatar\Students.xml; line: 2, column: 3]
I guess there is a problem with the annotations.I am a newbie to Jackson.So a help will be appreciated.