【发布时间】:2013-11-07 10:43:33
【问题描述】:
我正在尝试对我的嵌套实体使用 @JsonView 注释。 为了更清楚,假设我们有 2 个实体,每个实体都有自己的视图类。
public class JsonViewAddress {
//some view classes
}
public class Address {
//fields annotated by JsonViewAddress's classes and @JsonProperty
}
public class JsonViewPerson {
//some view classes
}
public class Person {
//some fields (yes annotated with JsonViewPerson classes and @JsonProperty)
//also assume that this is annotated with any JsonViewPerson's class.
private Address address;
}
让我们尝试从response中用Json类型来实现这个Person类
@Path("hey")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class Resource {
@GET
@Path("/stack/overflow")
@JsonView(value = { /* WHAT SHOULD BE WRITTEN HERE ? */ })
public Response method() {
//return Person entity in response
}
}
@JsonView 注释采用字符串数组,但我应该如何确定这些书面视图类必须为它们所属的每个实体显式工作?我想很快看到 UserView 适用于 User,AddressView 适用于 Address。
谢谢。
【问题讨论】:
标签: java json jackson jax-rs dropwizard