JBuilder as_json to_json

Does Jbuilder use as_json or to_json for rendering?

I am trying to override as_json and to_json with an alias like the one below:

  module BSON
    class ObjectId

      def as_json(*args)
        to_s
      end

      alias :to_json :as_json

    end
  end

      

Then use JBuilder to render the returned object. However, it acts as if it uses neither to_json nor as_json for rendering.

+3


source to share


1 answer


Jbuilder uses MultiJson which will use JSON gem by default. This gem is currently confused with the ActiveSupport all-Ruby #to_json implementation.



Link: http://www.rubydoc.info/gems/jbuilder/2.5.0

0


source







All Articles