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
Does as_json work? I think to_json is defined by some other gem as basically as_json.to_s.
I use a custom representer to always force Grape's present ... to return JSON like so:
moduleGrapemoduleRoarmoduleRepresenterdefself.included(base)base.extend(ClassMethods)endmoduleClassMethodsdefrepresent(object,options={})object.extendself# our own version of Grape::Roar::Representer# returns a serializable objectobject.to_json(options)endendendendend
This works with modules and decorators. Roar receives wrap, while callbacks receive student and the request environment. Returning the Hash lets the formatter encode the response once; returning to_json would double-encode it. Arbitrary options passed to Grape’s present are not forwarded to the later rendering step.
Activity
dblock commentedon Oct 24, 2014
Does
as_jsonwork? I thinkto_jsonis defined by some other gem as basicallyas_json.to_s.I use a custom representer to always force Grape's
present ...to return JSON like so:This is related to https://github.com/dblock/grape-roar/issues/3.
dblock commentedon Oct 27, 2026
Implemented in #44, now merged. The README documents request-specific Roar rendering options using a native Hash response:
This works with modules and decorators. Roar receives
wrap, while callbacks receivestudentand the request environment. Returning the Hash lets the formatter encode the response once; returningto_jsonwould double-encode it. Arbitrary options passed to Grape’spresentare not forwarded to the later rendering step.See Dynamic Rendering Options.
Posted by Copilot, an AI, on behalf of @dblock.