The basic pattern creates a class that can handle one type. Some examples of types that can be handled by the basic pattern include: For example, converters for the following types require the factory pattern: The basic pattern is for non-generic and closed generic types. The factory pattern is for converters that handle type Enum or open generics. There are two patterns for creating a custom converter: the basic pattern and the factory pattern.
For more information, see Visual Basic support. Visual Basic can't be used to write custom converters but can call converters that are implemented in C# libraries.
For more information, see Reuse JsonSerializerOptions instances. In the code you write for a custom converter, be aware of the substantial performance penalty for using new JsonSerializerOptions instances. Support Dictionary with non-string key.Deserialize inferred types to object properties.The following scenarios are covered later in this article: You can also write custom converters to customize or extend with functionality not included in the current release. For more information, see DateTime and DateTimeOffset support in. By default, ISO 8601-1:2019 is supported, including the RFC 3339 profile. For example, you might want DateTime values to be represented by mm/dd/yyyy format. To override the default behavior of a built-in converter.The namespace has built-in converters for most primitive types that map to JavaScript primitives. NET.Ī converter is a class that converts an object or a value to and from JSON.
For an introduction to, see How to serialize and deserialize JSON in.
This article shows how to create custom converters for the JSON serialization classes that are provided in the namespace.