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
serializeNameAttributeanddeserializeNameAttributein a generated serializer for use withname: attr() - Or, redefine
serializeDateAttributeanddeserializeDateAttributeto 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:
-
jsonObject
Returns:
(Resource) instance
_intersection
-
first -
second
Parameters:
-
firstArray -
secondArray
Returns:
_lookupFactory
-
type
Parameters:
-
typeString
Returns:
factory for creating resource instances
deserialize
-
json
Deserialize response objects from the request payload
Parameters:
-
jsonObject- response object, extract resource(s)
Returns:
deserializeIncluded
-
related -
resp
Deserialize optional included array of payload and add to service cache
Parameters:
-
relatedArray -
respObject(optional) e.g. headers, meta, etc.
deserializeResource
-
json
Deserialize response an object in the payload data
Parameters:
-
jsonObject
Returns:
deserializeResources
-
collection
Deserialize response objects in the payload data
Parameters:
-
collectionArray
Returns:
serialize
-
resource
Serialize resource for the request payload
Parameters:
-
resourceResource | Array- object to serialize
Returns:
serializeChanged
-
object
Serialize a resource object, but only the changed attributes
Parameters:
-
objectResourceto serialize
Returns:
serializeRelationship
-
resource -
relationship -
id
Parameters:
-
resourceResourceinstance, has URLs via it's relationships property
-
relationshipStringname
-
idString | Undefined(optional) of the related resource
Returns:
payload
serializeRelationships
-
resource -
relationships
Parameters:
-
resourceResourcewith relationships to serialize
-
relationshipsArraylist of {String} relationship properties
Returns:
the serialized relationship node for the JSON payload
serializeResource
-
object
Serialize a resource object
Parameters:
-
objectResourceto serialize
Returns:
serializeResources
-
collection
Parameters:
-
collectionArray
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:
-
jsonObjectwith 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
