|
@@ -44,11 +44,11 @@ namespace TEAMModelOS.SDK.DI
|
|
|
|
|
|
JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions()
|
|
|
{
|
|
|
- DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
|
|
+ // DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
|
|
};
|
|
|
var cm = CosmosClients.GetOrAdd(name, x => new CosmosClient(_optionsMonitor.Get(name).CosmosConnectionString, new CosmosClientOptions()
|
|
|
{
|
|
|
- // Serializer= new CosmosSystemTextJsonSerializer(jsonSerializerOptions),
|
|
|
+ Serializer= new CosmosSystemTextJsonSerializer(jsonSerializerOptions),
|
|
|
ApplicationRegion = region
|
|
|
}));
|
|
|
return cm;
|
|
@@ -66,44 +66,33 @@ namespace TEAMModelOS.SDK.DI
|
|
|
// <SystemTextJsonSerializer>
|
|
|
public class CosmosSystemTextJsonSerializer : CosmosSerializer
|
|
|
{
|
|
|
- private readonly JsonObjectSerializer systemTextJsonSerializer;
|
|
|
+ private readonly JsonSerializerOptions _serializerOptions;
|
|
|
|
|
|
public CosmosSystemTextJsonSerializer(JsonSerializerOptions jsonSerializerOptions)
|
|
|
{
|
|
|
- this.systemTextJsonSerializer = new JsonObjectSerializer(jsonSerializerOptions);
|
|
|
+ this._serializerOptions = jsonSerializerOptions;
|
|
|
}
|
|
|
|
|
|
public override T FromStream<T>(Stream stream)
|
|
|
{
|
|
|
using (stream)
|
|
|
{
|
|
|
- if (stream.CanSeek
|
|
|
- && stream.Length == 0)
|
|
|
- {
|
|
|
- return default;
|
|
|
- }
|
|
|
-
|
|
|
if (typeof(Stream).IsAssignableFrom(typeof(T)))
|
|
|
{
|
|
|
return (T)(object)stream;
|
|
|
}
|
|
|
-
|
|
|
- return (T)this.systemTextJsonSerializer.Deserialize(stream, typeof(T), default);
|
|
|
+ return JsonSerializer.Deserialize<T>(stream, _serializerOptions);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public override Stream ToStream<T>(T input)
|
|
|
{
|
|
|
- if (input!= null)
|
|
|
- {
|
|
|
- MemoryStream streamPayload = new MemoryStream();
|
|
|
- this.systemTextJsonSerializer.Serialize(streamPayload, input, input.GetType(), default);
|
|
|
- streamPayload.Position = 0;
|
|
|
- return streamPayload;
|
|
|
- }
|
|
|
- else {
|
|
|
- return new MemoryStream();
|
|
|
- }
|
|
|
+ var outputStream = new MemoryStream();
|
|
|
+ JsonSerializer.Serialize<T>(outputStream, input, _serializerOptions);
|
|
|
+
|
|
|
+ // A BREAKPOINT HERE AND A LOOK INSIDE 'outputStream' shows that ALL the fields have been serialized EXCEPT 'Id' or 'id.
|
|
|
+ outputStream.Position = 0;
|
|
|
+ return outputStream;
|
|
|
}
|
|
|
}
|
|
|
// </SystemTextJsonSerializer>
|