I have the requirement to return the result from the database either as a string in xml-structure or as json-structure. I\'ve got a solution, but I don\'t know, if this one
If someone using Spring Boot for XML response then add the following dependency,
com.fasterxml.jackson.dataformat
jackson-dataformat-xml
And in the model class you are returning add the @XmlRootElement
.
@Entity
@Table(name = "customer")
@XmlRootElement
public class Customer {
//... fields and getters, setters
}
and in your controller add produces="application/xml"
. This will produce the response in xml format.