Skip to content

Commit 23ed48e

Browse files
committed
[DEVEX-222] Ensured that metadata is serialized with auto-serialization as regular system metadata
1 parent 50f283c commit 23ed48e

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Diff for: src/KurrentDB.Client/Core/OperationOptions.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public record OperationOptions {
3131
public OperationOptions With(KurrentDBClientOperationOptions clientOperationOptions) =>
3232
new() {
3333
ThrowOnAppendFailure = ThrowOnAppendFailure ?? clientOperationOptions.ThrowOnAppendFailure,
34-
BatchAppendSize = BatchAppendSize ?? clientOperationOptions.BatchAppendSize
34+
BatchAppendSize = BatchAppendSize ?? clientOperationOptions.BatchAppendSize,
35+
Deadline = Deadline,
36+
UserCredentials = UserCredentials,
3537
};
3638
}

Diff for: src/KurrentDB.Client/Core/Serialization/MessageSerializer.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ public static IMessageSerializer With(
5454
}
5555

5656
class MessageSerializer(SchemaRegistry schemaRegistry) : IMessageSerializer {
57-
readonly ISerializer _jsonSerializer =
58-
schemaRegistry.GetSerializer(ContentType.Json);
57+
readonly SystemTextJsonSerializer _metadataSerializer =
58+
new SystemTextJsonSerializer(
59+
new SystemTextJsonSerializationSettings { Options = KurrentDBClient.StreamMetadataJsonSerializerOptions }
60+
);
5961

6062
readonly IMessageTypeNamingStrategy _messageTypeNamingStrategy =
6163
schemaRegistry.MessageTypeNamingStrategy;
@@ -74,7 +76,7 @@ public EventData Serialize(Message message, MessageSerializationContext serializ
7476
.Serialize(data);
7577

7678
var serializedMetadata = metadata != null
77-
? _jsonSerializer.Serialize(metadata)
79+
? _metadataSerializer.Serialize(metadata)
7880
: ReadOnlyMemory<byte>.Empty;
7981

8082
return new EventData(
@@ -106,8 +108,8 @@ public bool TryDeserialize(EventRecord record, [NotNullWhen(true)] out Message?
106108
}
107109

108110
object? metadata = record.Metadata.Length > 0 && TryResolveClrMetadataType(record, out var clrMetadataType)
109-
? _jsonSerializer.Deserialize(record.Metadata, clrMetadataType!)
110-
: null;
111+
? _metadataSerializer.Deserialize(record.Metadata, clrMetadataType!)
112+
: null;
111113

112114
deserialized = Message.From(data, metadata, record.EventId);
113115
return true;

Diff for: src/KurrentDB.Client/Streams/KurrentDBClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace KurrentDB.Client {
1313
/// The client used for operations on streams.
1414
/// </summary>
1515
public sealed partial class KurrentDBClient : KurrentDBClientBase {
16-
static readonly JsonSerializerOptions StreamMetadataJsonSerializerOptions = new() {
16+
internal static readonly JsonSerializerOptions StreamMetadataJsonSerializerOptions = new() {
1717
Converters = {
1818
StreamMetadataJsonConverter.Instance
1919
},

0 commit comments

Comments
 (0)