new Serializer(factory, modelManager)
Create a Serializer.
Note: Only to be called by framework code. Applications should
retrieve instances from Composer
Parameters:
| Name | Type | Description |
|---|---|---|
factory |
Factory | The Factory to use to create instances |
modelManager |
ModelManager | The ModelManager to use for validation etc. |
- Source:
Methods
-
fromJSON(jsonObject, options)
-
Create a Resource from a JavaScript Object representation.
The JavaScript Object should have been created by calling the
toJSON API.The Resource is populated based on the JavaScript object.
Parameters:
Name Type Description jsonObjectObject The JavaScript Object for a Resource
optionsObject the optional serialization options
Properties
Name Type Description acceptResourcesForRelationshipsboolean handle JSON objects
in the place of strings for relationships, defaults to false.Returns:
The new populated resource
- Type
- Resource
-
toJSON(resource, options)
-
Convert a Resource to a JavaScript object suitable for long-term
peristent storage.Parameters:
Name Type Description resourceResource The instance to convert to JSON
optionsObject the optional serialization options.
Properties
Name Type Description validateboolean validate the structure of the Resource
with its model prior to serialization (default to true)convertResourcesToRelationshipsboolean Convert resources that
are specified for relationship fields into relationships, false by default.permitResourcesForRelationshipsboolean Permit resources in the
place of relationships (serializing them as resources), false by default.- Source:
Throws:
-
- throws an exception if resource is not an instance of
Resource or fails validation.
- throws an exception if resource is not an instance of
- Type
- Error
Returns:
- The Javascript Object that represents the resource
- Type
- Object