SteveDunn / Vogen

A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
Apache License 2.0
888 stars 46 forks source link

JsonSerializerOptions doesnt seem to be passed through #679

Closed no1melman closed 1 month ago

no1melman commented 1 month ago

The source code in vogen shows this where on write the options are passed through:

https://github.com/SteveDunn/Vogen/blob/5ccd497ebd38846e535367cf062ea0c0c34808fa/src/Vogen/Templates/AnyOtherType/AnyOtherType_SystemTextJsonConverter.cs#L1-L33

But the auto gen gives me this

internal class DataRecordIdSystemTextJsonConverter : global::System.Text.Json.Serialization.JsonConverter<DataRecordId>
        {
            public override DataRecordId Read(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options)
            {
                var primitive = global::System.Text.Json.JsonSerializer.Deserialize<SurrealId>(ref reader, options);
                return DataRecordId.__Deserialize(primitive);
            }

            public override void Write(System.Text.Json.Utf8JsonWriter writer, DataRecordId value, global::System.Text.Json.JsonSerializerOptions options)
            {
                global::System.Text.Json.JsonSerializer.Serialize(writer, value.Value);
            }

#if NET6_0_OR_GREATER
            public override DataRecordId ReadAsPropertyName(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options)
            {
                var primitive = global::System.Text.Json.JsonSerializer.Deserialize<SurrealId>(ref reader, options);
                return DataRecordId.__Deserialize(primitive);
            }

            public override void WriteAsPropertyName(System.Text.Json.Utf8JsonWriter writer, DataRecordId value, global::System.Text.Json.JsonSerializerOptions options)
            {
                writer.WritePropertyName(global::System.Text.Json.JsonSerializer.Serialize(value.Value));
            }
#endif            
        }

Something seems to be askew

no1melman commented 1 month ago

Old 4.0.8 version...

SteveDunn commented 1 month ago

Thanks for the feedback @no1melman - I'm glad that it's working for you in the new version.