I'm currently using Jersey & Jackson for creating REST service. Right now when a Resource method produces application/json and is returned a POJO, it properly serializes the object into JSON and returns the response to the client.
What I'm looking to do now is setup Jersey so when a queryparam comes in (lets say "indent"), I can tell Jackson to serialize the JSON in a "prettier format, aka indented". You can easily tell Jackson to do this by configuring the JSON mapper with SerializationConfig.Feature.INDENT_OUTPUT.
The question is, how do I on a per-request basis take a queryparam and use that to modify Jackson's output?
Something like this:
@GET
@Path("path/to/rest/service")
@Produces("application/json")
public Response getSomething(
@DefaultValue("false") @QueryParam("indent") boolean indent, ...) {
...
if (indent) {
objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
}
...
}
Is what you looking for?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With