Class CosmosEntitySerializer
The provider's document serializer: System.Text.Json with web (camelCase) defaults, plus the store-neutral
modeling vocabulary — [StoredAs] renames the element, [Unmapped] keeps the member out of the
document, and the model's Converts registrations translate values both ways. It extends
CosmosLinqSerializer so the SDK's LINQ translation asks this serializer for member
names: a renamed member filters, sorts and projects against its stored name — the query can never
desynchronize from the document.
public sealed class CosmosEntitySerializer : CosmosLinqSerializer
- Inheritance
-
CosmosEntitySerializer
- Inherited Members
Constructors
CosmosEntitySerializer(JsonSerializerOptions)
Initializes the serializer over the given options (see CosmosClientFactory).
public CosmosEntitySerializer(JsonSerializerOptions options)
Parameters
optionsJsonSerializerOptionsThe System.Text.Json options.
Methods
BuildOptions(CosmosModel?)
Builds the provider's serializer options: web defaults, the modeling-annotation contract (renames and exclusions), and the model's value converters when a model is given.
public static JsonSerializerOptions BuildOptions(CosmosModel? model = null)
Parameters
modelCosmosModelThe Cosmos model whose
Convertsregistrations apply, ornull.
Returns
FromStream<T>(Stream)
Convert a Stream of JSON to an object. The implementation is responsible for Disposing of the stream, including when an exception is thrown, to avoid memory leaks.
public override T FromStream<T>(Stream stream)
Parameters
streamStreamThe Stream response containing JSON from Cosmos DB.
Returns
- T
The object deserialized from the stream.
Type Parameters
TAny type passed to Container.
SerializeMemberName(MemberInfo)
The element name the SDK's LINQ translation uses for memberInfo.
public override string SerializeMemberName(MemberInfo memberInfo)
Parameters
memberInfoMemberInfo
Returns
ToStream<T>(T)
Convert the object to a Stream. The caller will take ownership of the stream and ensure it is correctly disposed of. Stream.CanRead must be true.
public override Stream ToStream<T>(T input)
Parameters
inputTAny type passed to Container.
Returns
- Stream
A readable Stream containing JSON of the serialized object.
Type Parameters
T