jgr jgr - 1 year ago 72
reST (reStructuredText) Question

Spring Boot REST with XML Support

I made simple rest webservice with Spring Boot 1.2.5 and it works fine for json but i cant make this work to return xml.

This is my controller:

@RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
public List<Activity> getAllActivities() {
return activityRepository.findAllActivities();

When i call it with Accept: application/json everything works, but when i try with application/xml i get some HTML with 406 Error and message:

The resource identified by this request is only capable of generating responses
with characteristics not acceptable according to the request "accept" headers.

My model objects:

public class Activity {

private Long id;
private String description;
private int duration;
private User user;
//getters & setters...

public class User {

private String name;
private String id;

My pom.xml

<relativePath /> <!-- lookup parent from repository -->






Do i need some additional jars in my pom.xml to make this work? I tried adding jaxb-api or jax-impl but it didnt help.

jgr jgr
Answer Source

To make this work in Spring Boot without using Jersey we need to add this dependency:


The output will be a bit ugly but it works:


Here is nice tutorial: http://www.javacodegeeks.com/2015/04/jax-rs-2-x-vs-spring-mvc-returning-an-xml-representation-of-a-list-of-objects.html