You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Setting media type (json for eg) manually not working for certain cases. #482
But it works if I comment use(new Jackson()); out, not sure if this is expected.
Unfortunately, setting MediaType json manually doesn't work in deferred API and hence I'd need to resort to use(new Jackson()); to send JSON response from a deferred API by returning map (Jackson would convert to JSON)
changed the title [-]Customizing media type (json for eg) not working[/-][+]Setting media type (json for eg) manually not working for certain cases.[/+]on Sep 21, 2016
1-- writing raw json doesn't work bc Jackson outputs String, primitives or similar as valid JSON. There are a lot of discussion around this... but there is no formal/unique solution.
For this specific use case I suggest you to write a custom render, like:
/** Raw JSON renderer .*/renderer((value, ctx) -> {
if (valueinstanceofString && ctx.accepts(MediaType.json)) {
ctx.send(value.toString());
}
});
use(newJackson());
So, here you test for a String output and application/json and write directly.
Please note the custom renderer is on top of the Jackson module. Renderers in jooby are executed in the order they were provided.
2-- We do have a bug while returning results from Deferred API, this is now fixed and this is now possible:
Activity
[-]Customizing media type (json for eg) not working[/-][+]Setting media type (json for eg) manually not working for certain cases.[/+]jknack commentedon Sep 26, 2016
There two issues here:
1-- writing raw json doesn't work bc Jackson outputs String, primitives or similar as valid JSON. There are a lot of discussion around this... but there is no formal/unique solution.
For this specific use case I suggest you to write a custom render, like:
So, here you test for a String output and
application/jsonand write directly.Please note the custom renderer is on top of the Jackson module. Renderers in jooby are executed in the order they were provided.
2-- We do have a bug while returning results from
Deferred API, this is now fixed and this is now possible:paul-hammant commentedon Jan 30, 2018
Would love a one-liner for this:
stringsWillBeJson();