I made a simple web service to relax using Spring Boot 1.2.5, and it works fine for json, but I cannot get this work to return xml.
This is my controller:
@RestController
..
@RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
@ResponseStatus(HttpStatus.OK)
public List<Activity> getAllActivities() {
return activityRepository.findAllActivities();
}
When I call it with Accept: application / json, everything works, but when I try to use the / xml application, I get HTML code with error 406 and the 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:
@XmlRootElement
public class Activity {
private Long id;
private String description;
private int duration;
private User user;
}
@XmlRootElement
public class User {
private String name;
private String id;
}
My pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Do I need to add extra jars to my pom.xml to make this work? I tried adding jaxb-api or jax-impl, but it did not help.
jgr source
share