DS.UnderscoredSerializer Class
The UnderscoredSerializer is intended use when creating a subclass of the
DS.RESTSerializer.
Based on activemodel-adapter package, supports hasMany and belongsTo
records embedded in JSON payloads, designed to work out of the box with the
active_model_serializers
Ruby gem. And is designed to integrate with an API that uses an underscored
naming convention instead of camelCasing.
Constructor
DS.UnderscoredSerializer
()
Item Index
Methods
keyForAttribute
-
attribute
Converts camelCased attributes to underscored when serializing.
Parameters:
-
attributeString
Returns:
String
keyForRelationship
-
key -
kind
Underscores relationship names and appends "_id" or "_ids" when serializing relationship keys.
Parameters:
-
keyString -
kindString
Returns:
String
normalize
-
type -
hash -
prop
Add extra step to DS.RESTSerializer.normalize so links are normalized.
If your payload looks like:
{
"post": {
"id": 1,
"title": "Rails is omakase",
"links": { "flagged_comments": "api/comments/flagged" }
}
}
The normalized version would look like this
{
"post": {
"id": 1,
"title": "Rails is omakase",
"links": { "flaggedComments": "api/comments/flagged" }
}
}
Parameters:
-
typesubclass of DS.Model -
hashObject -
propString
Returns:
Object
normalizeLinks
-
hash
Convert snake_cased links to camelCase
Parameters:
-
hashObject
normalizeRelationships
()
private
Normalize the polymorphic type from the JSON.
Normalize:
{
id: "1"
minion: { type: "evil_minion", id: "12"}
}
To:
{
id: "1"
minion: { type: "evilMinion", id: "12"}
}
serializeIntoHash
-
hash -
type -
record -
options
Underscores the JSON root keys when serializing.
Parameters:
-
hashObject -
typesubclass of DS.Model -
recordDS.Model -
optionsObject
serializePolymorphicType
-
record -
json -
relationship
Serializes a polymorphic type as a fully capitalized model name.
Parameters:
-
recordDS.Model -
jsonObject -
relationshipObject
typeForRoot
-
root
Extracts the model typeKey from underscored root objects.
Parameters:
-
rootString
Returns:
String the model's typeKey
