Skip to content

DTO Deserialization

samatrhea edited this page Aug 21, 2024 · 5 revisions

Overview

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);

CDP4-COMET Optimized Deserialization

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.

ThingSerializer

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.

ClasslessDtoSerializer

The ClasslessDtoSerializer derives from the JsonConverter. The ReadJson method and and CanConvert are overriden to deserialize to a Classless-DTO.

Clone this wiki locally