MartenDB 序列化程序问题

问题描述 投票:0回答:1

最近迁移到最新版本的 MartenDB 6.4.0,并在尝试查询 postgres 数据库中的流事件列表时开始看到以下错误

代码

await _querySession.Events.AggregateStreamAsync<TAggregate>(id, token: cancellationToken)

System.InvalidCastException: Reading as 'System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' is not supported for fields having DataTypeName 'jsonb'
 ---> System.NotSupportedException: Type 'Dictionary`2' required dynamic JSON serialization, which requires an explicit opt-in; call 'EnableDynamicJson' on 'NpgsqlDataSourceBuilder' or NpgsqlConnection.GlobalTypeMapper (see https://www.npgsql.org/doc/types/json.html and the 8.0 release notes for more details). Alternatively, if you meant to use Newtonsoft JSON.NET instead of System.Text.Json, call UseJsonNet() instead.

mt_events 表负载示例

seq_id id 流_id 数据
10. 018d1b4e-e410-4071-a201-f8a796523c01 69a2d0c6-64ff-4b71-b850-c23014a5bc7f {“ID”:123”)

马丁配置

options.Events.MetadataConfig.HeadersEnabled = true;
                options.Events.MetadataConfig.CausationIdEnabled = true;
                options.Events.MetadataConfig.CorrelationIdEnabled = true;
                options.UseDefaultSerialization(EnumStorage.AsString,
                    nonPublicMembersStorage: NonPublicMembersStorage.All);

尝试过更改序列化器并降级 Martin 版本,但没有成功

.net event-sourcing marten
1个回答
0
投票

根据您收到的错误消息

JSON serialization, which requires an explicit opt-in; call 'EnableDynamicJson' 
,您现在需要明确选择动态 Json。

添加这一行对我有用。

NpgsqlConnection.GlobalTypeMapper.EnableDynamicJson();

请参阅 NPGSQL 的官方发行说明文档:

JSON POCO 和其他动态功能现在需要明确选择加入

© www.soinside.com 2019 - 2024. All rights reserved.