jsonapi-serializer/docs/json_serialization.md
2020-02-19 09:51:03 +00:00

716 B

JSON Serialization Support

Support for JSON serialization is no longer provided as part of the API of fast_jsonapi. This decision (see #12) is based on the idea that developers know better what library for JSON serialization works best for their project.

To bring back the old functionality, define the to_json or serialized_json methods with the relevant JSON library call. Here's an example on how to get it working with the popular oj gem:

require 'oj'
require 'fast_jsonapi'

class BaseSerializer
  include FastJsonapi::ObjectSerializer

  def to_json
    Oj.dump(serializable_hash)
  end
  alias_method :serialized_json, :to_json
end

class MovieSerializer < BaseSerializer
  # ...
end