We have a spring backed resteasy REST API implementation using Jackson.
I want to decide at runtime (inside my resource class) which JsonView should be used to serialize the 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;
}
}
I'm experimenting with a custom serializer but it seems as if the view can't be configured after an object mapper has been set up. What approach could be feasible to do that?