Fauna v10 .NET/C# Driver 0.2.0-beta
 
Loading...
Searching...
No Matches
CheckedSerializer.cs
Go to the documentation of this file.
1using Fauna.Mapping;
2
3namespace Fauna.Serialization;
4
5internal class CheckedSerializer<T> : BaseSerializer<T>
6{
7 public override T Deserialize(MappingContext context, ref Utf8FaunaReader reader)
8 {
9 var obj = DynamicSerializer.Singleton.Deserialize(context, ref reader);
10
11 if (obj is T v) return v;
12
13 throw new SerializationException(
14 $"Expected type {typeof(T)} but received {obj?.GetType()}");
15 }
16
17 public override void Serialize(MappingContext context, Utf8FaunaWriter writer, object? o)
18 {
19 DynamicSerializer.Singleton.Serialize(context, writer, o);
20 }
21}
A class representing the mapping context to be used during serialization and deserialization.