Skip to content

Commit ba4c484

Browse files
authored
Docs: Customizing: always pass options in samples
1 parent cff6551 commit ba4c484

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

docs/Customizing.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ type Location =
362362
// --> {"Case":"Address","Fields":{"address":"5 Avenue Anatole France"}}
363363
// (same as without UnwrapRecordCases)
364364
365-
JsonSerializer.Serialize(ExactLocation { lat = 48.858; long = 2.295 })
365+
JsonSerializer.Serialize(ExactLocation { lat = 48.858; long = 2.295 }, options)
366366
// --> {"Case":"ExactLocation","Fields":{"lat":48.858,"long":2.295}}
367367
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
368368
// Instead of {"Item":{"lat":48.858,"long":2.295}}
@@ -375,7 +375,7 @@ type Location =
375375
// --> {"Address":{"address":"5 Avenue Anatole France"}}
376376
// (same as without UnwrapRecordCases)
377377
378-
JsonSerializer.Serialize(ExactLocation { lat = 48.858; long = 2.295 })
378+
JsonSerializer.Serialize(ExactLocation { lat = 48.858; long = 2.295 }, options)
379379
// --> {"ExactLocation":{"lat":48.858,"long":2.295}}
380380
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
381381
// Instead of {"Item":{"lat":48.858,"long":2.295}}
@@ -388,7 +388,7 @@ type Location =
388388
// --> {"Case":"Address","address":"5 Avenue Anatole France"}
389389
// (same as without UnwrapRecordCases)
390390
391-
JsonSerializer.Serialize(ExactLocation { lat = 48.858; long = 2.295 })
391+
JsonSerializer.Serialize(ExactLocation { lat = 48.858; long = 2.295 }, options)
392392
// --> {"Case":"ExactLocation","lat":48.858,"long":2.295}
393393
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
394394
// Instead of {"Item":{"lat":48.858,"long":2.295}}
@@ -401,7 +401,7 @@ type Location =
401401
// --> {"address":"5 Avenue Anatole France"}
402402
// (same as without UnwrapRecordCases)
403403
404-
JsonSerializer.Serialize(ExactLocation { lat = 48.858; long = 2.295 })
404+
JsonSerializer.Serialize(ExactLocation { lat = 48.858; long = 2.295 }, options)
405405
// --> {"lat":48.858,"long":2.295}
406406
// Instead of {"Item":{"lat":48.858,"long":2.295}}
407407
```
@@ -525,7 +525,7 @@ It makes the parsing of union case names case-insensitive.
525525
JsonFSharpConverter(unionTagCaseInsensitive = true)
526526
|> options.Converters.Add
527527
528-
JsonSerializer.Deserialize<Example> """{"Case":"wIThArgS","Fields":[123,"Hello, world!"]}"""
528+
JsonSerializer.Deserialize<Example>("""{"Case":"wIThArgS","Fields":[123,"Hello, world!"]}""", options)
529529
// --> WithArgs (123, "Hello, world!")
530530
```
531531

@@ -546,10 +546,13 @@ type Point() =
546546
547547
type Rectangle = { BottomLeft: Point; TopRight: Point }
548548
549+
JsonFSharpConverter(allowNullFields = true)
550+
|> options.Converters.Add
551+
549552
// With allowNullFields = false: throws an exception
550-
JsonSerializer.Deserialize<Rectangle> """{"TopRight":{"X":1,"Y":2}}"""
553+
JsonSerializer.Deserialize<Rectangle>("""{"TopRight":{"X":1,"Y":2}}""", options)
551554
552555
// With allowNullFields = true: succeeds
553-
JsonSerializer.Deserialize<Rectangle> """{"TopRight":{"X":1,"Y":2}}"""
556+
JsonSerializer.Deserialize<Rectangle>("""{"TopRight":{"X":1,"Y":2}}""", options)
554557
// --> { BottomLeft = null; TopRight = Point(X = 1., Y = 2.) }
555558
```

0 commit comments

Comments
 (0)