Closed tylergets closed 8 years ago
Reference to the JSONApi documentation here: http://jsonapi.org/format/#crud-creating
Umm... I'm sorry for the ambiguous documentation. To serialize a Resource
as document, the Resource
object should be added to a Document
. Call either Resource.addTo(Document)
or Document.addData(Resource)
. Here is an example:
person.addTo(Document.create());
// or
Document doc = Document.create();
doc.addData(person);
// and then
moshi.adapter(Person.class).toJson(person);
// => { "data": { "type": "people", "attributes": { "first-name": "Yuki", "last-name": "Kiriyama", "twitter": "kamikat_bot" } } }
// alternatively, for list of resources
moshi.adapter(Person[].class).toJson(new Person[] { person });
// => { "data": [{ "type": "people", "attributes": { "first-name": "Yuki", "last-name": "Kiriyama", "twitter": "kamikat_bot" } }] }
According to the JSONAPIs documentation around Creating of CRUD resources, it shows that objects must be wrapped in a data tag like so
However, this package (as shown in the README) does not wrap the object inside the data attribute.
Is this intentional? It seems like a breaking change for many existing projects however I believe the goal of this package is to built to spec.