MtBaseJsonConverterT Class

Base class for business object JSON converters in the MobileTrack project. This class is created to provide a common base, to prevent code duplication.

Definition

Namespace: MobileTrack.Common.Services.JsonConverters.BusinessObjects
Assembly: MobileTrack.Common (in MobileTrack.Common.dll) Version: 0.7+45c8d9adb5970d727cceec44a5ed61aea0016e50
internal abstract class MtBaseJsonConverter<T> : JsonConverter<T>
where T : class
Inheritance
Object    JsonConverter    JsonConverterT    MtBaseJsonConverterT
Derived
More

Type Parameters

T
Business object the converter uses. Note: the constraint doesn't include IIdLabel since not all objects that we use this converter on are composed with that interface in mind.

Remarks

Write(Utf8JsonWriter, T, JsonSerializerOptions) is not overridden; Read(Utf8JsonReader, Type, JsonSerializerOptions), however is. This is because most overlapping code is in the reading part.

Constructors

MtBaseJsonConverterTInitializes a new instance of the MtBaseJsonConverterT class

Methods

CheckState Once the reader is done reading, we check the state of the item, whether it is valid.
In most cases this will invoke a method from ModelValidatorsExtensions that returns the boolean result and sets state.
GenerateItem Generates a new item of type T.
ReadReads and converts the JSON to type T.
(Overrides JsonConverterTRead(Utf8JsonReader, Type, JsonSerializerOptions))
ReadParameter Reads a parameter from the JSON reader and assigns the value to the property of item.

Exceptions

JsonException Thrown if the object doesn't start with a StartObject, ends with an EndObject or contains anything else than pairs of PropertyName and their values.
A property cannot have multiple values. (Note: a collection of objects counts as a single value, namely the collection itself, which starts/end with object or array start- and end tokens.)
It can also be thrown if the name of a PropertyName is .

See Also