Module: Utopia::Controller::Handlers::JSON

Defined in:
lib/utopia/controller/responder.rb

Overview

Serializes controller values as JSON responses.

Constant Summary collapse

APPLICATION_JSON =
Protocol::Media::Type.new("application", "json").freeze

Class Method Summary collapse

Class Method Details

.call(context, request, media_range, object, **options) ⇒ Object

Serialize an object as JSON.



28
29
30
31
32
33
34
# File 'lib/utopia/controller/responder.rb', line 28

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

.content_typeObject

The media type produced by this handler.



38
39
40
# File 'lib/utopia/controller/responder.rb', line 38

def self.content_type
	APPLICATION_JSON
end