Skip to content

STJ deserialize should behave the same on property without getter #116812

Closed
@ltbyun

Description

@ltbyun

Description

I faced multiple JsonProperty Name assigned to single property, and I followed it.
However, it only works on int, string properties, it not work on other reference types.

Reproduction Steps

run following code on .net8 runtime.

using System.Text.Json;

var item = JsonSerializer.Deserialize<Item>("""{"Id": 1, "Ids": [2]}""")!;
var itemFromAlias = JsonSerializer.Deserialize<Item>("""{"IdAlias": 1, "IdsAlias": [2]}""")!;
Console.WriteLine("item.Id=" + item.Id);
Console.WriteLine("itemFromAlias.Id=" + itemFromAlias.Id);
Console.WriteLine("item.Ids=" + item.Ids);
Console.WriteLine("itemFromAlias.Ids=" + itemFromAlias.Ids);

public class Item
{
    public int Id { get; set; }
    public int[] Ids { get; set; }

    public int IdAlias { set => Id = value; }
    public int[] IdsAlias { set => Ids = value; }
}

Expected behavior

it prints

item.Id=1
itemFromAlias.Id=1
item.Ids=System.Int32[]
itemFromAlias.Ids=System.Int32[]

Actual behavior

it prints

item.Id=1
itemFromAlias.Id=1
item.Ids=System.Int32[]
itemFromAlias.Ids=

itemFromAlias.Ids should not be null if itemFromAlias.Id is not default

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions