Skip to content

Fails to deserialize when changing naming policy. #1

@dulfe

Description

@dulfe

The naming policy seems to be ignored.

Changing the PropertyNamingPolicy to CamelCase has no effect, it does not throw an exception and returns the object with its defaults.

For example, this test fails:

    [Fact]
    public void SerializeProperlyWhenNamingPolicyIsNotTheDefault()
    {
      var jsonString = @"{""id"":3, ""title"": ""Title""}";
      var deserializeOptions = new JsonSerializerOptions()
      {
        PropertyNamingPolicy = JsonNamingPolicy.CamelCase
      };
      deserializeOptions.SetMissingMemberHandling(MissingMemberHandling.Error);

      var response = JsonSerializer.Deserialize<WeatherForecast>(jsonString, deserializeOptions);
      
      response.Title.ShouldBe("Title");
    }

But, it works if I remove the line:

deserializeOptions.SetMissingMemberHandling(MissingMemberHandling.Error);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions