Class Transform
public
Module:
@ember-data/serializer
The Transform
class is used to serialize and deserialize model
attributes when they are saved or loaded from an
adapter. Subclassing Transform
is useful for creating custom
attributes. All subclasses of Transform
must implement a
serialize
and a deserialize
method.
Example
app/transforms/temperature.js
// Converts centigrade in the JSON to fahrenheit in the app
export default class TemperatureTransform {
deserialize(serialized, options) {
return (serialized * 1.8) + 32;
}
serialize(deserialized, options) {
return (deserialized - 32) / 1.8;
}
static create() {
return new this();
}
}
Usage
```js {data-filename=app/models/requirement.js} import Model, { attr } from '@ember-data/model';
export default class RequirementModel extends Model {