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 Json.NET library provides means to customize and control how objects are deserialized. The JsonSerializer is used for deserialization, using the JsonConverter for optimized DTO and Classless-DTO deserialization.
The ThingSerializer derives from the JsonConverter. The ReadJson
method and and CanConvert
are overriden to deserialize to a DTO. The static DtoFactory implements the ToDto
extension method that converts a JObject to a DTO using the any of the *MapResolver
static classes.
The ClasslessDtoSerializer derives from the JsonConverter. The ReadJson
method and and CanConvert
are overriden to deserialize to a Classless-DTO.