JsonConvertWithAttribute

Namespace: SnowBank.Data.Json · class

Implements: Attribute

Attaches a CrystalJson custom converter to a member or a type

Remarks

The named type is honored for whichever of IJsonPacker (packing) and IJsonDeserializer (deserializing) it implements for the decorated member's type (or the decorated type itself) - a type that is only ever written or only ever read may implement a single facet, and any attempt to use the missing direction fails with an exception naming the facet to implement. The common symmetric case implements both, e.g. via the IJsonMemberConverter bundle or a source-generated IJsonConverter. A type implementing neither facet throws: at metadata construction on the reflection path, and as build error CJSON0010 through the source generator.

When to use which attribute: the System.Text.Json spelling [JsonConverter(typeof(...))] is also recognized, but it is only legitimate when the named converter is valid for System.Text.Json as well (both serializers then do the same thing). A CrystalJson-only converter behind the STJ attribute poisons the type for STJ (runtime InvalidOperationException, or a build error from the STJ source generator); such converters must use THIS attribute instead, which System.Text.Json never inspects.

When both this attribute and a foreign spelling are present, this one wins.

Constructors

JsonConvertWithAttribute

JsonConvertWithAttribute(Type converterType)

Properties

ConverterType

Type ConverterType { get; }

Type of the converter, which must implement the IJsonPacker + IJsonDeserializer pair