Allow an ID of object to be customized directly on the serializer by
passing a block to `set_id` as opposed to only through a model property.
We already allow for attributes that do not have a model property of the
same name to be customized directly on the serializer using a block.
This customization can be useful in situation in which you have
different classes being serialized using the same serializer. For
example, if we have `HorrorMovie`, `ComedyMovie` and `DramaMovie` using
the same `MovieSerializer`, we can unify their IDs using
```
class MovieSerializer
include FastJsonapi::ObjectSerializer
attributes :name, :year
set_id do |record|
"#{record.name.downcase}-#{record.id}"
end
```
which is preferable to creating a `#serialized_id` method in every model
that will use `MovieSerializer` to encapsulate the customization.
Closes#315
Core extensions do not play well with many other gems; especially
considering that they only seem to be included for one `to_json` call,
they should be avoided.
If you forgot to set any `has_many` in the serializer and tried to serialize with an `include` you would get:
```
NoMethodError (undefined method `[]' for nil:NilClass):
```
That is not very helpful. Setting the variable with a default case makes sure the right error message gets displayed.
* add hash benchmarking to performance tests
* Add missing attribute in README example
* Disable GC before doing performance test
* Enable oj to AM for fair benchmark test
* add information on performance methodology
* add oss metadata
* Make an error that demonstrates [Issue
* Simple RSpec test that fails with a non-empty string but passes with a
non-empty symbol
* To run the test, rspec spec/lib/object_serializer_spec.rb
* Map includes to symbols if they are provided as strings
* Includes would fail with an ArgumentError unless they were explicitly
provided as symbols (see #97)
* This is solved by mapping the strings to symbols in the
ObjectSerializer initializer
* No real impact on performance here