module JSON
Serializes controller values as JSON responses.
Definitions
def self.call(context, request, media_range, object, **options)
Serialize an object as JSON.
Signature
-
parameter
contextObject The context.
-
parameter
requestUtopia::Request The request.
-
parameter
media_rangeProtocol::HTTP::Header::Accept::MediaRange The negotiated media range.
-
parameter
objectObject The object.
-
parameter
optionsHash The options.
-
returns
String The serialized JSON body.
Implementation
def self.call(context, request, media_range, object, **options)
if version = media_range.parameters["version"]
options[:version] = version.to_s
end
return object.to_json(options)
end
def self.content_type
The media type produced by this handler.
Signature
-
returns
Protocol::Media::Type The JSON media type.
Implementation
def self.content_type
APPLICATION_JSON
end