Cant wrap my head around this. This is my xml file
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user>
<username>Tom</username>
<password>123</password>
</user>
<user>
<username>Moc</username>
<password>1234</password>
</user>
</users>
And these are my classes in Java:
Users.java
@Data
public class Users {
private List<User> user;
}
User.java
@Data
public class User {
private String username;
private String password;
}
For some reason I am constantly getting error: "com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "user"
My loading method is here:
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("Users.xml").getFile());
String xmlContent = XMLReader(new FileInputStream(file));
XmlMapper xmlMapper = new XmlMapper();
Users users = xmlMapper.readValue(xmlContent, Users.class);
XMLReader is just method which reads xml file line by line. Thanks for help in advance.