-
#154: Add
SkippableOptionFieldsenum to further customize the skipping of fields of typeoptionandvoptionwithWithSkippableOptionFields.SkippableOptionFields.FromJsonSerializerOptionsis the default and equivalent toWithSkippableOptionFields(false): fields of typeoptionandvoptionare skipped if used withJsonIgnoreCondition.WhenWritingNull.SkippableOptionFields.Alwaysis equivalent toWithSkippableOptionFields(true): fields of typeoptionandvoptionare always skipped.SkippableOptionFields.Never: fields of typeoptionandvoptionare never skipped.
-
#159: Throw an exception when trying to deserialize
nullinto a record or union in any context, rather than only when they are in fields of records and unions. -
#160: Fix
WithSkippableOptionFields(false)not working forvoption. -
#161: Allow using single-case unions as keys in all dictionary types.
NOTE: This requires System.Text.Json 8.0.
-
#162: Add option
.WithMapFormat(MapFormat)to customize the format of F# maps.MapFormat.Objectalways serializes maps as objects. The key type must be supported as key for dictionaries. NOTE: This requires System.Text.Json 8.0.MapFormat.ArrayOfPairsalways serializes maps as JSON arrays whose items are[key,value]pairs.MapFormat.ObjectOrArrayOfPairsis the default: maps whose keys are string or single-case unions wrapping string are serialized as JSON objects, and other maps are serialized as JSON arrays whose items are[key,value]pairs.
-
#163: Add
StructuralComparisonto the typeSkippable<_>. -
#164: When deserializing a record with
JsonIgnoreCondition.WhenWritingNull, when a non-nullable field is missing, throw a properJsonExceptionrather than aNullReferenceException.
-
#141: Add fluent options builder.
JsonFSharpOptionshas the following new methods:- static methods that create options with default settings:
.Default(),.NewtonsoftLike(),.FSharpLuLike()and.ThothLike(). - instance methods
.WithOptionAbc(?bool)for each flagJsonUnionEncoding.Abc, that sets or unsets this option and returns a newJsonFSharpOptions. - instance methods
.WithAbc(value)for each optional argumentabcof its constructor, that sets this option and returns a newJsonFSharpOptions. - an instance method
.ToJsonSerializerOptions()that returns a newJsonSerializerOptionswith the correspondingJsonFSharpConverterconfigured. - an instance method
.AddToJsonSerializerOptions(options)that takes an existingJsonSerializerOptions, configures the correspondingJsonFSharpConverterand returnsunit.
The above is now the recommended way of configuring the library, and future options may be only made available using fluent methods and not using constructor arguments.
- static methods that create options with default settings:
-
#146: Add option
.WithSkippableOptionFields(?bool)that makes fields of typeoptionandvoptionbehave likeSkippable:None/ValueNoneis represented by a missing field instead of anullvalue.This is equivalent to the pre-1.0 default behavior, and is now recommended if this behavior is desired instead of
IgnoreNullValues = trueorDefaultIgnoreCondition = WhenWritingNull.
-
#89: Add
JsonNameAttributeas a more powerful substitute for the standardJsonPropertyNameAttribute.- When used on a discriminated union case,
JsonNameAttributecan take a value of typeintorboolinstead ofstring. JsonNameAttributecan take multiple values. When deserializing, all these values are treated as equivalent. When serializing, the first one is used.JsonNameAttributehas a settable propertyField: string. It is used to set the JSON name of a union case field with the given name.
- When used on a discriminated union case,
-
#92: Serialization of record properties (in addition to fields).
- Add option
includeRecordProperties: boolto enable serializing record properties. - Also serialize record properties with
JsonIncludeAttributeeven whenincludeRecordPropertiesis false.
- Add option
-
Add support for the standard
DefaultIgnoreCondition.WhenWritingNullas a synonym forIgnoreNullValues = truethat allowsNoneandValueNoneto be omitted instead ofnull. -
#106: Fix deserialization of single-case union containing a legitimate
nullvalue. -
#123: BREAKING CHANGE: Missing fields of type
optionorvoptionnow throw an error by default instead of being deserialized toNone/ValueNone. To support missing fields, either enable the optionIgnoreNullValues = trueorDefaultIgnoreCondition = WhenWritingNull, or use the typeSkippableinstead ofoptionorvoption. -
#126: Add option
types: JsonFSharpTypesthat specifies which types the F# converter should handle. Unlisted types will be handled by the defaultSystem.Text.Json. By default, all supported types are handled.
-
#111: Support
JsonKnownNamingPolicyinJsonFSharpConverterAttribute. -
#112: Add
OptionsandOverridesproperties toJsonFSharpConverter. -
#263: Add a nullary constructor for JsonFSharpConverter.
-
#98: Implement
JsonPropertyOrderAttributeon records. -
#108: Allow serializing unnamed union fields using their type name, instead of
Item1etc, usingJsonUnionEncoding.UnionFieldNamesFromTypes. -
#100: Allow unionTagName to be part of the record type definition when deserializing union of records.
-
#109: Add .xml with documentation comments to nupkg. Thanks @exyi!
-
#110: Allow customizing the naming policy for union fields with
unionFieldNamingPolicy.
If not provided, useJsonSerializerOptions.PropertyNamingPolicyas before.
-
#87: Fix null checking on value type fields.
-
#93: Allow deserializing F# unions in
AdjacentTagandInternalTagmodes where the tag is not the first field in the JSON object. This capability is enabled by new optionJsonUnionEncoding.AllowUnorderedTag, which is included inJsonUnionEncoding.Defaultand allJsonUnionEncoding.*Likecombined formats.
- #83: Fix null reference exception when deserializing a record that
Skips a field with FSharp.Core 5.0. - Remove netcoreapp3.0 specific build.
- #77: Fix compile-time error when publishing a trimmed .NET 5 application. Thanks @pchalamet!
- #71: Allow overriding specific types in
JsonFSharpConverterwith new argumentoverrides. These override even types that haveJsonFSharpConverterAttributewhenallowOverride = true.
- #69: Allow overriding
JsonFSharpConverteroptions withJsonFSharpConverterAttributeby passingallowOverride = truetoJsonFSharpConverter. - Add
JsonUnionEncoding.Inherit. When this flag is set on aJsonFSharpConverterAttributethat overrides aJsonFSharpConverter, this type still uses theJsonFSharpConverter'sJsonUnionEncoding.
- #56: Add
JsonUnionEncoding.UnwrapRecordCases, which impliesJsonUnionEncoding.NamedFieldsand encodes union cases containing a single record field as if the record's fields were the union's fields instead. For example:This option is compatible with all union formats (type U = | U of r: {| x: int; y: bool |} U {| x = 1; y = true |} // Serialized as: {"Case":"U","Fields":{"x":1,"y":true}} // Instead of: {"Case":"U","Fields":{"r":{"x":1,"y":true}}}
AdjacentTag,ExternalTag,InternalTagandUntagged). - #64: Fix serialization of
unitas field of an F# type. Thanks @NickDarvey!
-
#54: Do throw an exception when a mandatory field is missing and an optional field was omitted. Thanks @fuchen!
-
#57: Do throw an exception when a parsed value is null inside an array, a set or a tuple, unless
allowNullFieldsis true. Thanks @drhumlen!
- #47: Add
Skippable<'T>to represent values that can be omitted from the serialization of a record or a union withNamedFields. This is particularly useful withSkippable<'T option>(orvoption) to represent a field that can be omitted, null, or have a proper value.Also add atype R = { x: Skippable<int option> } { x = Skip } // Serialized as: {} { x = Include None } // Serialized as: {"x":null} { x = Include (Some 42) } // Serialized as: {"x":42}
Skippablemodule with standard functions:map,filter, etc. Implementation largely based on @cmeeren's JsonSkippable which provides the same functionality for Newtonsoft.Json. - #51: When the type
Kis a single-case union wrapping a string, serializeMap<K, V>into a JSON object, likeMap<string, V>.
- #43: In deserialization, allow omitting fields that are optional.
-
#30: Unwrap
'T voptionwithJsonUnionEncoding.UnwrapOption. -
#32: Add
JsonUnionEncoding.UnwrapSingleFieldCases, which encodes the field of single-field cases asxinstead of[x]. Include it inJsonUnionEncoding.FSharpLuLike. -
#33: Fix "read too much or not enough" when parsing a list of unions with
JsonUnionEncoding.UnwrapFieldlessTags. -
#38: Add more consistent names for options:
BareFieldlessTagsbecomesUnwrapFieldlessTags;SuccintOptionbecomesUnwrapOption;EraseSingleCaseUnionsbecomesUnwrapSingleCaseUnions.
The previous names are marked
Obsolete.
- #3: Add support for
PropertyNamingPolicyon record and union fields. - #22: Add support for
DictionaryKeyPolicyforMap<string, 'T>. - #27: Add
unionTagNamingPolicyoption toJsonFSharpConverterandJsonFSharpConverterAttributeto customize the naming policy for union tag names. - #26: Add
JsonUnionEncoding.EraseSingleCaseUnions, which encodes single-case single-field unions the same as the value in the field.
BREAKING CHANGE: This is now the default option. - #5: Add support for
PropertyNameCaseInsensitiveon record and union fields.
AddunionTagCaseInsensitiveoption toJsonFSharpConverterandJsonFSharpConverterAttributeto customize the case sensitivity for union tag names.
- #4: Add support for standard option
IgnoreNullValueson record and union fields. - #13: Add support for
JsonPropertyNameAttributeon union cases to set the tag name to use for this case. - #16: Add
JsonUnionEncoding.SuccintOption, which encodesSome xthe same asx.
BREAKING CHANGE: This is now the default option. - Add
unionTagNameandunionFieldsNameoption to customize the"Case"and"Fields"tags for unions. - Add
JsonUnionEncoding.FSharpLuLike, which is equivalent toExternalTag ||| BareFieldlessTags ||| SuccintOption.
- #17: Add encoding of collections:
'T listencoded as JSON array.Set<'T>encoded as JSON array.Map<string, 'T>encoded as JSON object with map keys as field names.Map<'K, 'V>when'Kis notstringencoded as JSON array whose elements are[key,value]JSON arrays.- Tuples and struct tuples encoded as JSON array.
- #6: Add different encodings for F# unions.
JsonFSharpConverterandJsonFSharpConverterAttributenow takeJsonUnionEncodingas optional argument.- Unions are encoded depending on the
JsonUnionEncodingas detailed in the documentation.
- #9: Cache the result of
FSharpType.IsRecordandFSharpType.IsUnion - #12: Target .NET Standard 2.0 rather than .NET Core 3.0
- #1: Add support for
JsonPropertyNameAttributeon record fields - #2: Add support for
JsonIgnoreAttributeon record fields
- Serialize records
- Serialize unions with Newtonsoft-like format