From 90f7243c6b90cfe4e3aadf9cebc8db10041dfa63 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Tue, 15 May 2018 15:36:06 -0400 Subject: [PATCH] Update README --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 13973811..e7df25f2 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ the time you spend writing boilerplate serialization code for your models. * [Models](#models) * [Field Aliases](#aliases) * [Excluding Keys](#excluding-keys) + * [Required Fields](#required-fields) * [Serialization](#serializaition) * [Nesting](#nesting) * [ID and Date Fields](#id-and-dates) @@ -184,6 +185,25 @@ abstract class _Whisper extends Model { } ``` +## Required Fields +It is easy to mark a field as required; just use the +`@required` annotation from `package:meta`: + +```dart +@serializable +abstract class _Foo extends Model { + @required + int myRequiredInt; + + @Required('Custom message') + int myOtherRequiredInt; +} +``` + +The given field will be marked as `@required` in the +generated constructor, and serializers will check for its +presence, throwing a `FormatException` if it is missing. + # Nesting `angel_serialize` also supports a few types of nesting of `@serializable` classes: * As a class member, ex. `Book myField`