O'Reilly logo

Domain Modeling Made Functional by Scott Wlaschin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Complete Serialization Example

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required