DTO Deserialization - STARIONGROUP/COMET-SDK-Community-Edition GitHub Wiki
The CDP4JsonSerializer supports the deserialization of a C# object and is performance optimized for DTO objects and the Classless-DTO. The following snippet demonstrates how to deserialize a JSON Stream
to an IEnumerable<Thing>
.
// assume a json stream is coming from a web resource
var metadataprovider = new MetaDataProvider();
var serializer = new Cdp4JsonSerializer(this.metadataprovider, new Version(1, 1, 0));
var dtos = serializer.Deserialize(stream);
The system.text.json library provides means to customize and control how objects are deserialized.
The ThingSerializer derives from JsonConverter<T>
. The Read
method and and CanConvert
are overriden to deserialize to a DTO. The static DtoFactory implements the ToDto
extension method that converts a JsonElement
to a DTO using the any of the *Resolver
static classes.
The ClasslessDtoSerializer derives from JsonConverter<T>
. The Read
method and and CanConvert
are overriden to deserialize to a Classless-DTO.