JsonBooleanLiteralsConverter

Namespace: SnowBank.Data.Json · class

Implements: IJsonMemberConverter<bool>, IJsonPacker<bool>, IJsonDeserializer<bool>

Converter installed for members carrying JsonBooleanLiteralsAttribute; feeds the same per-member converter slot as [JsonConverter(typeof(...))]

Remarks

Public because generated converters instantiate it directly; application code normally uses the attribute instead.

Constructors

JsonBooleanLiteralsConverter

JsonBooleanLiteralsConverter(object whenFalse, object whenTrue, bool strictLiterals = false)

Specifies the output literals for this member

  • whenFalse — Output form of false: a String, a Boolean, or a numeric value (ex: "0", 0). Pass null to NOT EMIT the member at all when the value is false, for a consumer that expects either the member absent or the true literal.
  • whenTrue — Output form of true: a String, a Boolean, or a numeric value (ex: "1", 1). It may not be null: emitting nothing for true has no meaning.

The two arguments do not have to share a type: [JsonBooleanLiterals("0", 1)] is legal, because legacy outputs are not always consistent.

Methods

Pack

JsonValue Pack(ref CrystalJsonPackContext context, bool instance)

Unpack

bool Unpack(JsonValue value, ICrystalJsonTypeResolver resolver)