JasperFx / marten

.NET Transactional Document DB and Event Store on PostgreSQL
https://martendb.io
MIT License
2.88k stars 458 forks source link

NodaTime projection deserialization exception #2866

Open jposert opened 11 months ago

jposert commented 11 months ago

Hello everyone. When trying to use NodaTime along with the project, I receive an exception:

System.Text.Json.JsonException: Cannot convert value to NodaTime.Instant
 ---> NodaTime.Text.UnparsableValueException: The value string does not match a quoted string in the pattern. Value being parsed: '2023-12-16T22:49:58.999361^+00:00'. (^ indicates error position.)
   at NodaTime.Text.ParseResult`1.GetValueOrThrow()
   at NodaTime.Text.ParseResult`1.get_Value()
   at NodaTime.Serialization.SystemTextJson.NodaPatternConverter`1.ReadJsonImpl(Utf8JsonReader& reader, JsonSerializerOptions options)
   at NodaTime.Serialization.SystemTextJson.NodaConverterBase`1.Read(Utf8JsonReader& reader, Type objectType, JsonSerializerOptions options)
   --- End of inner exception stack trace ---
   at NodaTime.Serialization.SystemTextJson.NodaConverterBase`1.Read(Utf8JsonReader& reader, Type objectType, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
   at System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter`5.TryRead[TArg](ReadStack& state, Utf8JsonReader& reader, JsonParameterInfo jsonParameterInfo, TArg& arg)
   at System.Text.Json.Serialization.Converters.SmallObjectWithParameterizedConstructorConverter`5.ReadAndCacheConstructorArgument(ReadStack& state, Utf8JsonReader& reader, JsonParameterInfo jsonParameterInfo)
   at System.Text.Json.Serialization.Converters.ObjectWithParameterizedConstructorConverter`1.ReadConstructorArgumentsWithContinuation(ReadStack& state, Utf8JsonReader& reader, JsonSerializerOptions options)
   at System.Text.Json.Serialization.Converters.ObjectWithParameterizedConstructorConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.ContinueDeserialize(ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsync(Stream utf8Json, CancellationToken cancellationToken)
   at Marten.Services.SystemTextJsonSerializer.FromJsonAsync[T](Stream stream, CancellationToken cancellationToken)
   at Marten.Services.SystemTextJsonSerializer.FromJsonAsync[T](DbDataReader reader, Int32 index, CancellationToken cancellationToken)
   at Marten.Services.SystemTextJsonSerializer.FromJsonAsync[T](DbDataReader reader, Int32 index, CancellationToken cancellationToken)
   at Marten.Linq.Selectors.SerializationSelector`1.ResolveAsync(DbDataReader reader, CancellationToken token)
   at Marten.Linq.QueryHandlers.ListQueryHandler`1.HandleAsync(DbDataReader reader, IMartenSession session, CancellationToken token)
   at Marten.Linq.MartenLinqQueryProvider.ExecuteHandlerAsync[T](IQueryHandler`1 handler, CancellationToken token)
   at Marten.Linq.MartenLinqQueryProvider.ExecuteHandlerAsync[T](IQueryHandler`1 handler, CancellationToken token)
   at JasperFx.Core.Exceptions.ExceptionTransformExtensions.TransformAndThrow(IEnumerable`1 transforms, Exception ex)
   at JasperFx.Core.Exceptions.ExceptionTransforms.TransformAndThrow(Exception ex)
   at Marten.Exceptions.MartenExceptionTransformer.WrapAndThrow(Exception exception)
   at Marten.Linq.MartenLinqQueryProvider.ExecuteHandlerAsync[T](IQueryHandler`1 handler, CancellationToken token)
   at Marten.Linq.MartenLinqQueryable`1.ToListAsync[TResult](CancellationToken token)
...

I found an issue that probably concerns exactly the same thing #1276 - is it possible that the error has started occurring again? As I already mentioned, the problem occurs only in the case when I use the Select projection - when I retrieve the whole document, deserialization works correctly. The Marten configuration looks as follows:

options.UseDefaultSerialization(
    serializerType: SerializerType.SystemTextJson
);
options.UseNodaTime();

Tested with: Marten: 6.4.0 / 7.0.0-beta.2 NodaTime: 3.1.9 Npgsql: 8.0.0

jeremydmiller commented 11 months ago

Also see:

[Theory]
[InlineData(SerializerType.SystemTextJson)]
[InlineData(SerializerType.Newtonsoft)]
public void bug_1276_can_select_instant(SerializerType serializerType)
{
    return; // TODO -- FIX THIS