ruby-grape / grape

An opinionated framework for creating REST-like APIs in Ruby.
http://www.ruby-grape.org
MIT License
9.88k stars 1.22k forks source link

ArgumentError: coerce_with disallowed for type: JSON #1653

Open ktimothy opened 7 years ago

ktimothy commented 7 years ago

If I want, for instance, to use Oj library to parse JSON, grape does not allow me to do so.

requires :json, type: Array[JSON], coerce_with: ->(raw) { Oj.load(raw) }

What are the reasons for that? Maybe we can allow custom coercions for JSON?

dblock commented 7 years ago

Probably just not implemented, I'll leave this open as a feature request, please feel free to contribute.

Grape < 1.0 uses multi_json, so just adding Oj makes use of that everywhere. I think for > 1.0 that's the strategy you want to take, and it's fully supported, see https://github.com/ruby-grape/grape#json-and-xml-processors.

ktimothy commented 7 years ago

Well, Oj was probably not the best example. I'll try to implement it tomorrow unless anything crashes =)