January 2018
Beginner to intermediate
312 pages
7h 22m
English
To demonstrate the practice of serializing and deserializing a domain object to and from JSON, let’s build a small example. Say that we want to persist a domain type Person that’s defined like this:
| | module Domain = // our domain-driven types |
| | |
| | /// constrained to be not null and at most 50 chars |
| | type String50 = String50 of string |
| | |
| | /// constrained to be bigger than 1/1/1900 and less than today's date |
| | type Birthdate = Birthdate of DateTime |
| | |
| | /// Domain type |
| | type Person = { |
| | First: String50 |
| | Last: String50 |
| | Birthdate : Birthdate |
| | } |
The String50 and Birthdate types cannot be serialized directly, so we first create a corresponding DTO type Dto.Person (a Person in a Dto module) ...
Read now
Unlock full access