CultureInfoConverter Class
A custom JSON converter for System.Globalization.CultureInfo objects. It allows for the serialization and deserialization of System.Globalization.CultureInfo instances when working with JSON data.
public class CultureInfoConverter : System.Text.Json.Serialization.JsonConverter<System.Globalization.CultureInfo>Inheritance System.Object → System.Text.Json.Serialization.JsonConverter → System.Text.Json.Serialization.JsonConverter<System.Globalization.CultureInfo> → CultureInfoConverter
Methods
CultureInfoConverter.Read(Utf8JsonReader, Type, JsonSerializerOptions) Method
Reads and converts the JSON to a System.Globalization.CultureInfo.
public override System.Globalization.CultureInfo Read(ref System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options);Parameters
reader System.Text.Json.Utf8JsonReader
The reader to read the JSON from.
typeToConvert System.Type
The type of object to convert to.
options System.Text.Json.JsonSerializerOptions
The serializer options to use.
Returns
System.Globalization.CultureInfo
The deserialized System.Globalization.CultureInfo object.
Exceptions
System.Text.Json.JsonException
Thrown when the JSON token is not a string or null, or if the string is not a valid culture identifier.
CultureInfoConverter.Write(Utf8JsonWriter, CultureInfo, JsonSerializerOptions) Method
Writes a specified System.Globalization.CultureInfo object as JSON.
public override void Write(System.Text.Json.Utf8JsonWriter writer, System.Globalization.CultureInfo value, System.Text.Json.JsonSerializerOptions options);Parameters
writer System.Text.Json.Utf8JsonWriter
The writer to write the JSON to.
value System.Globalization.CultureInfo
The System.Globalization.CultureInfo value to convert.
options System.Text.Json.JsonSerializerOptions
The serializer options to use.
Remarks
If the System.Globalization.CultureInfo is System.Globalization.CultureInfo.InvariantCulture, it writes a null value; otherwise, it writes the culture name as a string.