Parsing JSON Payload in Rails When Using Custom MIME Type

For those who may be interested, I found the answer to my own question.

Use something like this in mime_types.rb (or possibly elsewhere in your your initialization sequence):

ActionController::Base.param_parsers[Mime::Type.lookup('application/vnd.com.example.foo+json')]=lambda do |body|
  JSON.parse body
end

One catch: don't use capitalization in the MIME type above (i.e., 'application/vnd.com.example.Foo+json'). Rails converts the MIME type into all lower case, so no match will be found it it's set to upper case.


In Rails 5 do:

ActionDispatch::Request.parameter_parsers[Mime::Type.lookup('application/vnd.api+json').symbol] = lambda do |body|
  JSON.parse(body)
end

In Rails 3 do:

ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime::Type.lookup('application/vnd.com.example.foo+json')]=lambda do |body|
  JSON.parse(body)
end