我有一个非常简单的对象,我想以JSON返回
public class Event {
private String store;
private Date date;
private double fee;
private String kit;
private String information;
和测试控制器如下
@RestController
@EnableWebMvc
public class UserController {
@RequestMapping(value = "/user/{username}", method = RequestMethod.GET, produces = "application/json", headers="Accept=*/*")
@ResponseBody
public Event getUser(@PathVariable("username") String username){
Event event = new Event("dummy", new Date(), 4.0, "dummy", "dummy");
return event;
}
}
我得到“此请求标识的资源只能根据请求“接受”标头生成特性不可接受的响应。”
我的servlet只有此条目
<mvc:annotation-driven />
如何获得所需的输出?
最佳答案
添加
dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.0</version>
</dependency>