jackson-annotations
jackson-annotations copied to clipboard
Use 2 different `@JsonView` in a method (parameter and return)
Allow using one view as input and a different view of the same DTO as output to a method. Like this :
@POST
@Path("/add")
@JsonView(parameter=ExempleViews.Ajout.class, return=ExempleViews.Response.class) // <-- like this
@APIResponse(responseCode = "201", description = "Add with success")
@APIResponse(responseCode = "400", description = "Bad request")
@APIResponse(responseCode = "409", description = "Conflict in database")
@APIResponse(responseCode = "500", description = "Internal error")
public Uni<Response> add(@Valid @NotNull ExampleDto exampleDto) {
return exampleService
.add(exampleDto)
.map(e -> Response.ok(e).status(Status.CREATED).build());
}
Ok so:
- Functionality used via annotations is defined elsewhere (even in case of regular
@JsonView, handling provided by jackson-databind, so this request would only be for specific change to@JsonViewtype (but not to that adding new functionality) - I don't think existing semantics of
@JsonViewshould be changed (confusing to existing users since it would have no meaning for regular view handling). More likely a new annotation should be created; one that could use@JsonViewas parameter type for 2 properties - Since handling is not (cannot) be part of any of Jackson core packages, new annotation does not belong here.
In practice I think this would be adding annotation in whatever framework is being used: Spring Boot, Quarkus -- or, if JAX-RS / Jakarta-RS, to
- https://github.com/FasterXML/jackson-jaxrs-providers/
- https://github.com/FasterXML/jackson-jakarta-rs-providers/