Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectJsonSerializerSettingsExtensions

Namespace: AdCodicem.ValueObjects.NewtonsoftJson
Assembly: AdCodicem.ValueObjects.NewtonsoftJson.dll

Wires value object support into .

public static class ValueObjectJsonSerializerSettingsExtensions

Inheritance​

object ← ValueObjectJsonSerializerSettingsExtensions

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Methods​

AddValueObjects(JsonSerializerSettings, bool)​

Adds to the settings, with the two settings it reads value objects best under.

public static JsonSerializerSettings AddValueObjects(this JsonSerializerSettings settings, bool decimalReals = true)

Parameters​

settings JsonSerializerSettings

Settings to configure.

decimalReals bool

true to set ; false to leave as the settings have it.

Returns​

JsonSerializerSettings

The same settings, so calls can be chained.

Remarks​

Newtonsoft.Json reads each token under its settings before a converter sees it. This sets , so that a string that looks like a date reaches the converter as the text it is, rather than as a date converted to local time, which a string or a value object cannot be read back from.

keeps every digit of a value object, where the default reads it through a : 12.50 would read back as 12.5, and 1234567890123456789.12 as 1234567890123456800. It applies to every number of the payload, so pass false when a payload carries a or a beyond the range of a , about ±7.9 × 10^28, which makes the reader throw under it, or one smaller than its 28 decimal places, which loses the digits past them.

The converter is added once: a registration already in the settings is left alone.

It leaves as it is: is for code that hands Newtonsoft.Json a contract resolver alone.