mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
updating readme and changelog
This commit is contained in:
parent
61ac3ad0ff
commit
867d36a3a3
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,8 +1,12 @@
|
|||||||
### 0.10.0
|
### 0.10.0
|
||||||
|
|
||||||
|
* adds adapters pattern
|
||||||
* adds support for `meta` and `meta_key` [@kurko]
|
* adds support for `meta` and `meta_key` [@kurko]
|
||||||
* adds method to override association [adcb99e, @kurko]
|
* adds method to override association [@kurko]
|
||||||
* adds `has_one` attribute for backwards compatibility [@ggordon]
|
* adds `has_one` attribute for backwards compatibility [@ggordon]
|
||||||
* updates JSON API support to RC3 [@mateomurphy]
|
* adds JSON API support 1.0 [@benedikt]
|
||||||
* adds fragment cache support [@joaomdmoura]
|
* adds fragment cache support [@joaomdmoura]
|
||||||
* adds cache support to attributes and associations [@joaomdmoura]
|
* adds cache support to attributes and associations [@joaomdmoura]
|
||||||
|
* uses model name to determine the type [@lsylvester]
|
||||||
|
* remove root key option and split JSON adapter [@joaomdmoura]
|
||||||
|
* adds FlattenJSON as default adapter [@joaomdmoura]
|
||||||
32
README.md
32
README.md
@ -8,7 +8,7 @@ AMS does this through two components: **serializers** and **adapters**.
|
|||||||
Serializers describe _which_ attributes and relationships should be serialized.
|
Serializers describe _which_ attributes and relationships should be serialized.
|
||||||
Adapters describe _how_ attributes and relationships should be serialized.
|
Adapters describe _how_ attributes and relationships should be serialized.
|
||||||
|
|
||||||
By default AMS will use the **Json Adapter**. But we strongly advise you to use JsonApi Adapter that follows 1.0 of the format specified in [jsonapi.org/format](http://jsonapi.org/format).
|
By default AMS will use the **Flatten Json Adapter**. But we strongly advise you to use **JsonApi Adapter** that follows 1.0 of the format specified in [jsonapi.org/format](http://jsonapi.org/format).
|
||||||
Check how to change the adapter in the sections bellow.
|
Check how to change the adapter in the sections bellow.
|
||||||
|
|
||||||
# RELEASE CANDIDATE, PLEASE READ
|
# RELEASE CANDIDATE, PLEASE READ
|
||||||
@ -66,6 +66,12 @@ ActiveModel::Serializer.config.adapter = :json_api
|
|||||||
You won't need to implement an adapter unless you wish to use a new format or
|
You won't need to implement an adapter unless you wish to use a new format or
|
||||||
media type with AMS.
|
media type with AMS.
|
||||||
|
|
||||||
|
If you want to have a root key on your responses you should use the Json adapter, instead of the default FlattenJson:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
ActiveModel::Serializer.config.adapter = :json
|
||||||
|
```
|
||||||
|
|
||||||
If you would like the key in the outputted JSON to be different from its name in ActiveRecord, you can use the :key option to customize it:
|
If you would like the key in the outputted JSON to be different from its name in ActiveRecord, you can use the :key option to customize it:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
@ -130,17 +136,7 @@ The key can be customized using `meta_key` option.
|
|||||||
render json: @post, meta: { total: 10 }, meta_key: "custom_meta"
|
render json: @post, meta: { total: 10 }, meta_key: "custom_meta"
|
||||||
```
|
```
|
||||||
|
|
||||||
`meta` will only be included in your response if there's a root. For instance,
|
`meta` will only be included in your response if you are using an Adapter that supports `root`, as JsonAPI and Json adapters, the default adapter (FlattenJson) doesn't have `root`.
|
||||||
it won't be included in array responses.
|
|
||||||
|
|
||||||
### Root key
|
|
||||||
|
|
||||||
If you want to define a custom root for your response, specify it in the `render`
|
|
||||||
call:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
render json: @post, root: "articles"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Overriding association methods
|
### Overriding association methods
|
||||||
|
|
||||||
@ -176,9 +172,19 @@ end
|
|||||||
|
|
||||||
### Built in Adapters
|
### Built in Adapters
|
||||||
|
|
||||||
|
#### FlattenJSON
|
||||||
|
|
||||||
|
It's the default adapter, it generates a json response without a root key.
|
||||||
|
Doesn't follow any specifc convention.
|
||||||
|
|
||||||
|
#### JSON
|
||||||
|
|
||||||
|
It also generates a json response but always with a root key. The root key **can't be overridden**, and will be automatically defined accordingly with the objects being serialized.
|
||||||
|
Doesn't follow any specifc convention.
|
||||||
|
|
||||||
#### JSONAPI
|
#### JSONAPI
|
||||||
|
|
||||||
This adapter follows RC4 of the format specified in
|
This adapter follows 1.0 of the format specified in
|
||||||
[jsonapi.org/format](http://jsonapi.org/format). It will include the associated
|
[jsonapi.org/format](http://jsonapi.org/format). It will include the associated
|
||||||
resources in the `"included"` member when the resource names are included in the
|
resources in the `"included"` member when the resource names are included in the
|
||||||
`include` option.
|
`include` option.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user