<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.12.4</version>
</dependency>
public class Student {
private String name;
private int age;
// getters and setters
}
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
public class Main {
public static void main(String[] args) throws Exception {
XmlMapper xmlMapper = new XmlMapper();
Student student = new Student();
student.setAge(18);
String xmlString = xmlMapper.writeValueAsString(student);
System.out.println(xmlString);
Student deserializedStudent = xmlMapper.readValue(xmlString, Student.class);
System.out.println(deserializedStudent.getName());
System.out.println(deserializedStudent.getAge());
}
}