Skip to content

Commit 3aeb34b

Browse files
committed
Add docs for deserialization.
1 parent 53c59a1 commit 3aeb34b

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This is the documentation of ActiveModelSerializers, it's focused on the **0.10.
1313
- [Rendering](general/rendering.md)
1414
- [Caching](general/caching.md)
1515
- [Logging](general/logging.md)
16+
- [Deserialization](general/deserialization.md)
1617
- [Instrumentation](general/instrumentation.md)
1718
- [JSON API Schema](jsonapi/schema.md)
1819
- [ARCHITECTURE](ARCHITECTURE.md)

docs/general/deserialization.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[Back to Guides](../README.md)
2+
3+
# Deserialization
4+
5+
This is currently an *experimental* feature. The interface may change.
6+
7+
## JSON API
8+
9+
The `ActiveModelSerializers::Deserialization` defines two methods (namely `jsonapi_parse` and `jsonapi_parse!`), which take a `Hash` or an instance of `ActionController::Parameters` representing a JSON API payload, and return a hash that can directly be used to create/update models. The bang version throws an `InvalidDocument` exception when parsing fails, whereas the "safe" version simply returns an empty hash.
10+
11+
- Parameters
12+
- document: `Hash` or `ActionController::Parameters` instance
13+
- options:
14+
- only: `Array` of whitelisted fields
15+
- except: `Array` of blacklisted fields
16+
- keys: `Hash` of fields the name of which needs to be modified (e.g. `{ :author => :user, :date => :created_at }`)
17+
18+
Example:
19+
20+
```ruby
21+
class PostsController < ActionController::Base
22+
def create
23+
Post.create(create_params)
24+
end
25+
26+
def create_params
27+
ActiveModelSerializers::Deserialization.jsonapi_parse(params, only: [:title, :content, :author])
28+
end
29+
end
30+
```
31+
32+
## Attributes/Json
33+
34+
There is currently no deserialization for those adapters.

0 commit comments

Comments
 (0)