-
Notifications
You must be signed in to change notification settings - Fork 37
Closed
Description
When the data for a relationship of an object is passed in as an instance of an ES2015 class, json-api-serializer seems unable to properly read the object, returning a relationship with data: { type: 'sometype', id: '[object Object]' } instead of correctly reading the id and placing the data under included.
See below for full reproduction case:
const JSONAPISerializer = require('json-api-serializer');
const Serializer = new JSONAPISerializer();
Serializer.register('article', {
id: 'id',
relationships: { author: { type: 'author' } }
});
Serializer.register('author', {
id: 'id'
});
class Author {
constructor({ id, name }) {
this.id = id;
this.name = name;
}
}
const articleData = {
id: '1',
author: new Author({
id: '2',
name: 'John Jacob Jingleheimer Schmidt'
})
};
console.log(Serializer.serialize('article', articleData));
Metadata
Metadata
Assignees
Labels
No labels