Skip to content

[Bug]: SystemTextJsonContentSerializer.GetFieldNameForProperty(PropertyInfo) does not use the provided JsonSerializerOptions #1481

Description

@othmane-kinane-nw

Describe the bug 🐞

The value returned by SystemTextJsonContentSerializer.GetFieldNameForProperty(PropertyInfo) doesn't match the provided JsonSerializerOptions.PropertyNamingPolicy

Step to reproduce

using System.Reflection;
using System.Text.Json;
using Refit;
using Xunit;

public class SystemTextJsonContentSerializerTests
{
    private record CustomDto(string MyProperty);

    [Fact]
    public void field_name_should_match_the_provided_PropertyNamingPolicy()
    {
        JsonSerializerOptions jsonOptions = new()
        {
            PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        };
        SystemTextJsonContentSerializer contentSerializer = new(jsonOptions);
        PropertyInfo propertyInfo = typeof(CustomDto).GetProperty(nameof(CustomDto.MyProperty))!;
        string? fieldName = contentSerializer.GetFieldNameForProperty(propertyInfo);
        Assert.Equal("myProperty", fieldName);
    }
}

Reproduction repository

No response

Expected behavior

fieldName value should be myProperty instead of null.

Screenshots 🖼️

No response

IDE

No response

Operating system

No response

Version

No response

Device

No response

ReactiveUI Version

No response

Additional information ℹ️

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bug🔤 area: serializationJSON (STJ/Newtonsoft), content serializers, converters🟢 priority: lowNiche feature, edge case, or low-impact request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions