3. Let's Serialize

You can encode and decode objects using the global dogs variable. All default serializer expand the dogs engine instance with <format>Encode and <format>Decode methods taking a required generic type argument and a value to encode or decode. This could look something like this:

  var encoded = dogs.jsonEncode<Person>(person); // Returns a string
  var decoded = dogs.jsonDecode<Person>(encoded); // Returns a 'Person'

You can also encode and decode list, sets, and other iterables using the respective methods:

  var encoded = dogs.jsonEncodeList<Person>([personA,personB]);
  var decoded = dogs.jsonDecodeList<Person>(encoded);

Last updated