Looks like serializing of annotated object with nested annotated objects via toJson() are not supported or I am completely don't understand how to do it.
Calling method toJson() even for your Person object (which is in your example along with nested Order and Item, code unchanged) fails to include serialized output of nested objects into final output.
Order order1 = new Order()
..count = 2
..itemNumber = 1
..isRushed = true
..item = new Item()
..itemNumber = 234
..isRushed=false;
Person person = new Person('Alexey', 'Kartavenko', new DateTime.now(), orders: <Order>[order1]);
print(person.toJson());
Result:
{firstName: Alexey, lastName: Kartavenko, date-of-birth: 2017-10-07T15:15:11.616592, last-order: null, orders: [Instance of 'Order']}
Looking into generated model code I don't see any attempts to call toJson() method of Order object. Is this by design or am I missing something obvious here?
Ah, I see. I need not to call person.toJson() directly but pass person to JSON.encode().
FWIW - I did the same thing and spent some time spinning on this. Might be good to show a little more usage in the readme to prevent others from the same issue.
Ah, I see. I need not to call person.toJson() directly but pass person to JSON.encode().
.... This is so stupid.
Most helpful comment
Ah, I see. I need not to call person.toJson() directly but pass person to JSON.encode().