Skip to content

Commit b65291c

Browse files
committed
Update README.md
1 parent 50b041c commit b65291c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This library is up-to-date with the finalized v1 JSON API spec.
1919
* [More customizations](#more-customizations)
2020
* [Base URL](#base-url)
2121
* [Root metadata](#root-metadata)
22+
* [Explicit serializer discovery](#explicit-serializer-discovery)
2223
* [Relationships](#relationships)
2324
* [Compound documents and includes](#compound-documents-and-includes)
2425
* [Relationship path handling](#relationship-path-handling)
@@ -313,6 +314,20 @@ You can pass a `meta` argument to specify top-level metadata:
313314
JSONAPI::Serializer.serialize(post, meta: {copyright: 'Copyright 2015 Example Corp.'})
314315
```
315316

317+
### Explicit serializer discovery
318+
319+
By default, jsonapi-serializers assumes that the serializer class for `Namespace::User` is `Namespace::UserSerializer`. You can override this behavior on a per-object basis by implementing the `jsonapi_serializer_class_name` method.
320+
321+
```ruby
322+
class User
323+
def jsonapi_serializer_class_name
324+
'SomeOtherNamespace::CustomUserSerializer'
325+
end
326+
end
327+
```
328+
329+
Now, when a `User` object is serialized, it will use the `SomeOtherNamespace::CustomUserSerializer`.
330+
316331
## Relationships
317332

318333
You can easily specify relationships with the `has_one` and `has_many` directives.

0 commit comments

Comments
 (0)