Legivel


Legivel.Mapper Processing Options

Calling Deserialize will run the yaml-to-model conversion with default options.

With the DeserializeWithOptions, you can customize your yaml processing.

Cross Check

By default, the model is leading, which means that any extra yaml in the source document will be ignored as long as it minimally includes all content required for the target model. With the processing option MappingMode you can require cross-check between content and model.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
type ProcessingOptionsType = {
    Name  : string
    EMail : string option
}

let yml = "
Name: Frank
#   below must cause a warning bc they're not part of the target type
Should Give A Warning : Morning
"

DeserializeWithOptions<ProcessingOptionsType> [MappingMode(MapYaml.WithCrossCheck)] yml

Which results in:

[Succes
   {Data = {Name = "Frank";
            EMail = None;};
    Warn =
     [{Location = (l4, c1);
       Message =
        "Field 'Should Give A Warning' cannot be mapped to target type 'FSI_0044+ProcessingOptionsType'";}];}]

Cross checking has the following options:

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
//  (default) The model is leading, any extra yaml content is ignored
MapYaml.ToModelOnly     

//  Cross-Check the yaml to the model (in certain cases), extra yaml causes warnings
MapYaml.WithCrossCheck  

//  Cross-Check the yaml to the model (in certain cases), extra yaml causes errors
MapYaml.AndRequireFullProjection

certain cases: Record types.

namespace Legivel
module Serialization

from Legivel
namespace System
type ProcessingOptionsType =
  {Name: string;
   EMail: string option;}
ProcessingOptionsType.Name: string
Multiple items
val string : value:'T -> string

--------------------
type string = String
ProcessingOptionsType.EMail: string option
type 'T option = Option<'T>
val yml : string
val DeserializeWithOptions : options:ProcessingOption list -> yaml:string -> DeserializeResult<'tp> list
union case ProcessingOption.MappingMode: MapYaml -> ProcessingOption
type MapYaml =
  | ToModelOnly = 0
  | WithCrossCheck = 1
  | AndRequireFullProjection = 2
Fork me on GitHub