我们有一个使用 Jackson 的 spring 支持的 resteasy REST API 实现。
我想在运行时(在我的资源类中)决定应该使用哪个 JsonView 来序列化 HttpResponse。
@Path("/foos")
public FooResource {
@GET
@Path("/{id}")
HttpResponse<FooRepresentation> getById(@PathParam("id") @NotNull String id);
}
public class FooRepresentation {
@JsonView(Views.Short.class)
private String name;
private String description;
}
publi class FooResourceImpl {
public HttpResponse<FooRepresentation> getById(String id) {
Foo foo = ...;
// How to decide here to use e.g. the Views.Short.class view?
return foo;
}
}
我正在尝试使用自定义序列化程序,但似乎在设置对象映射器后无法配置视图。什么方法可以做到这一点?