Add fluent options builder #141
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new fluent syntax to define the options of the converter.
New API:
.Default(),.NewtonsoftLike(),.ThothLike(),.FSharpLuLike()that create options with the correspondingJsonUnionEncoding..WithUnionFoo(?bool)for every enum caseJsonUnionEncoding.Foo;.WithFoo(value)for every optional argumentfooof theJsonFSharpConverterconstructor..ToJsonSerializerOptions()creates aJsonSerializerOptionswith an F# converter;.AddToJsonSerializerOptions(options)adds the F# converter to an existingJsonSerializerOptions, useful to integrate with ASP.NET Core, Giraffe, or other libraries.Advantages:
JsonFSharpConverterconstructor is binary-breaking (see Congrats on 1.0, please avoid binary breaking changes 😊 #132), whereas adding a fluent method isn't.JsonSerializerOptionsin a single expression, without having to create it and then mutate it. Especially useful when creating global options in a module.Unresolved questions:
JsonFSharpConverterAttribute? Since it's an attribute, it can't be fluent. Perhaps it should have settable properties that do the same thing as corresponding fluent methods, eg: