选择JsonView以在运行时序列化HttpResponse

时间:2015-04-17 14:27:25

标签: json spring jackson resteasy json-view

我们使用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;
    }
}

我正在尝试使用自定义序列化程序,但似乎在设置了对象映射器后无法配置视图。这样做有什么方法可行?

0 个答案:

没有答案
相关问题