ApplicationSerializer Class
Serializer/Deserializer for a JSON API resource object, used by adapter.
When extending use a mixin or define transform methods to serialize and/or deserializer attributes based on the name or the type of attribute.
The methods use a naming convention:
- '[de]serialize' + 'AttrName' or 'TypeName' + 'Attribute'
- E.g. use
serializeNameAttribute
anddeserializeNameAttribute
in a generated serializer for use withname: attr()
- Or, redefine
serializeDateAttribute
anddeserializeDateAttribute
to use your own data transformation withattr('date')
the default, Date type [de]serialize methods transfrom to/from ISO Format. - Transform methods based on the name of the attribute will be called instead of any transform methods based on the type of the attribute.
Item Index
Methods
_createResourceInstance
-
json
Create a Resource from a JSON API Resource Object
Parameters:
-
json
Object
Returns:
(Resource) instance
_intersection
-
first
-
second
Parameters:
-
first
Array -
second
Array
Returns:
_lookupFactory
-
type
Parameters:
-
type
String
Returns:
factory for creating resource instances
deserialize
-
json
Deserialize response objects from the request payload
Parameters:
-
json
Object- response object, extract resource(s)
Returns:
deserializeIncluded
-
related
-
resp
Deserialize optional included array of payload and add to service cache
Parameters:
-
related
Array -
resp
Object(optional) e.g. headers, meta, etc.
deserializeResource
-
json
Deserialize response an object in the payload data
Parameters:
-
json
Object
Returns:
deserializeResources
-
collection
Deserialize response objects in the payload data
Parameters:
-
collection
Array
Returns:
serialize
-
resource
Serialize resource for the request payload
Parameters:
-
resource
Resource | Array- object to serialize
Returns:
serializeChanged
-
object
Serialize a resource object, but only the changed attributes
Parameters:
-
object
Resourceto serialize
Returns:
serializeRelationship
-
resource
-
relationship
-
id
Parameters:
-
resource
Resourceinstance, has URLs via it's relationships property
-
relationship
Stringname
-
id
String | Undefined(optional) of the related resource
Returns:
payload
serializeRelationships
-
resource
-
relationships
Parameters:
-
resource
Resourcewith relationships to serialize
-
relationships
Arraylist of {String} relationship properties
Returns:
the serialized relationship
node for the JSON payload
serializeResource
-
object
Serialize a resource object
Parameters:
-
object
Resourceto serialize
Returns:
serializeResources
-
collection
Parameters:
-
collection
Array
Returns:
transformAttributes
-
json
-
[operation='deserialize']
Transform attributes, serialize or deserialize by specified method or per type of attribute, e.g. date.
Your serializer may define a specific method for a type of attribute,
i.e. serializeDateAttribute
and/or deserializeDateAttribute
. Likewise,
your serializer may define a specific method for the name of an attribute,
like serializeUpdatedAtAttribute
and deserializeUpdatedAtAttribute
.
During transformation a method based on the name of the attribute takes priority over a transform method based on the type of attribute, e.g. date.
Parameters:
-
json
Objectwith attributes hash of resource properties to be transformed
-
[operation='deserialize']
String optionalperform a serialize or deserialize operation, the default operation is to deserialize when not passed
Returns:
json