

You can also use a block to define a url as shown in custom_url.This is bugging me quite often now and I want to know more.
#Json compare gem movie
You can configure the method to use on the object for example a link with key self will get set to the value returned by a method called url on the movie object. In this example, public_url is expected to be a property of the object being serialized. By default, links are read directly from the model property of the same name. The block syntax can also be used to override the property on the object: class MovieSerializerĪttributes can also use a different name by passing the original method or accessor with a proc shortcut: class MovieSerializer In this example, name is expected to be a property of the object being serialized: class MovieSerializerĬustom attributes that must be serialized but do not exist on the model can be declared using Ruby block syntax: class MovieSerializer This method is also aliased as attribute, which is useful when defining a single attribute.īy default, attributes are read directly from the model property of the same name.

Set_key_transform :underscore # "some_key" => "some_key"Īttributes are defined using the attributes method. Set_key_transform :dash # "some_key" => "some-key" Set_key_transform :camel_lower # "some_key" => "someKey" Here are examples of how these options transform the keys set_key_transform :camel # "some_key" => "SomeKey" # Available options :camel, :camel_lower, :dash, :underscore(default) Here is the syntax of specifying a key transform class MovieSerializer It supports the same key transforms that are supported by AMS. Key Transformsīy default fast_jsonapi underscores the key names. If your serializer class name does not follow this format, you have to manually state the set_type at the serializer. For example class MovieSerializer will automatically have a type of :movie. Return Serialized JSON json_string = MovieSerializer.new(movie).serializable_hash.to_jsonīy default fast_jsonapi will try to figure the type based on the name of the serializer class. Object Serialization Return a hash hash = MovieSerializer.new(movie).serializable_hash Serializer Definition class MovieSerializer This will create a new serializer in app/serializers/movie_serializer.rb Model Definition class MovieĪttr_accessor :id, :name, :year, :actor_ids, :owner_id, :movie_type_id
#Json compare gem generator
You can use the bundled generator if you are using the library inside ofĪ Rails project: rails g serializer Movie name year

Please read the performanceĪrticle in the docs folder for any questions related to methodology. The performance provided by the alternatives. Implementations as part of performance tests available atĬhange on this library, serialization time stays significantly faster than We compare serialization times with ActiveModelSerializer and alternative

We would like to thank the Netflix team for the initial work and to all ourĬontributors and users for the continuous support! Performance Comparison Previously this project was called fast_jsonapi, we forked the projectĪnd renamed it to jsonapi/serializer in order to keep it alive.
#Json compare gem free
Please feel free to leave comments in the v3 Pull Request.Ī fast JSON:API serializer for Ruby Objects. We'll gladly accept bugfixes and security-related fixes for v2 (the master branch), but at this stage, contributions for new features/improvements are welcome only for v3. JSON:API Serialization Library :warning: :construction: v2 (the master branch) is in maintenance mode! :construction: :warning:
