Deserializing Relationships With Embedded Data
steven-mays opened this issue · 3 comments
I want to deserialize a relationship with embedded data. Do you have a recommended way of handling that within jsona
?
Example:
{
links: {},
data: {
type: 'characters',
id: '1234',
attributes: {
name: 'Mickey'
},
relationships: {
skills: {
data: [{
type: 'skills',
id: 'swords',
attributes: {
level: 20
}
}, {
type: 'skills',
id: 'bows',
attributes: {
level: 3
}
}]
}
}
}
}
Deserializes to:
{ type: 'characters',
id: '1234',
name: 'Mickey',
skills:
[ { type: 'skills', id: 'swords' },
{ type: 'skills', id: 'bows' } ],
relationshipNames: [ 'skills' ] }
What I'm looking to for:
{ type: 'characters',
id: '1234',
name: 'Mickey',
skills:
[ { type: 'skills', id: 'swords', level: 20 },
{ type: 'skills', id: 'bows', level: 3 } ],
relationshipNames: [ 'skills' ] }
Actually, embedded data, like attributes should be in ‘included’ part of json. Your approach is a violation of the spetification.
But yo can do it with jsona, by creating your own propertyMappers
See how customize at the end of README
@olosegres Any tips you can give with writing a propertyMapper in javascript within a node project?
I was wrong about possibility to do it with custom propertyMappers, to make it work you need to do changes to the library, but this is a violation of the specification, so I offer you to fork jsona and make changes you need there.