module Roda::RodaPlugins::Json

def self.configure(app, opts=OPTS)

Set the classes to automatically convert to JSON, and the serializer to use.
def self.configure(app, opts=OPTS)
  app.plugin :custom_block_results
  classes = opts[:classes] || [Array, Hash]
  app.opts[:json_result_classes] ||= []
  app.opts[:json_result_classes] += classes
  classes = app.opts[:json_result_classes]
  classes.uniq!
  classes.freeze
  classes.each do |klass|
    app.opts[:custom_block_results][klass] = :handle_json_block_result
  end
  app.opts[:json_result_serializer] = opts[:serializer] || app.opts[:json_result_serializer] || app.opts[:json_serializer] || :to_json.to_proc
  app.opts[:json_result_include_request] = opts[:include_request] if opts.has_key?(:include_request)
  app.opts[:json_result_content_type] = opts[:content_type] || 'application/json'.freeze
end