Marshalizer
Introduction
Marshalizer provide an easy reusable way to format data you send for render. With Marshalizer, you can use any object (ORM models/custom classes/etc.).
Thanks to the output_fields, you can define what attribute will be present in the returned object.
Basic Usage
var marshalizer = ;var book_output_field = id: name: ; app;
If you have a document from database like:
book = id: "47478fds4fd4s894fdszab8" name: 'Poney book' __v: 0 super_secret_data: 'my beautiful secret' price: 105
The result of:
marshalizer;
will return:
id: "47478fds4fd4s894fdszab8" name: 'Poney book'
Renaming Attribute
Because sometime, your sent data has not to be as the private data, you can define the public key of the object by giving the 'attribute' keyword
book_output_fields = 'id': marshalizerfield 'name': marshalizerfield
Define your own field
Your custom field must extends marshalizer.field.RawField
Example
RawField { superconfig } { return Stringprice + '$'; }
Then, you can use it:
var book_output_field = id: name: ; app
Nested Fields
Sometimes, we have documents into others. For example, books can contain author informations
var author_output_field = firstname: lastname: age: Number var book_output_field = id: name: author: field: author_output_field; app