Skip to content

ObservableProperty seems to break JSON Deserialization when used with JsonSerializerContext #893

@karmeye

Description

@karmeye

Describe the bug

Using this, the property is not populated with the json value.

[ObservableProperty]
[property: JsonPropertyName("from_uuid")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
private string? fromUuid;

However, if I write it manually it works.

[JsonPropertyName("from_uuid")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? FromUuid
{
    get => fromUuid;
    set
    {
        if (!EqualityComparer<string?>.Default.Equals(fromUuid, value))
        {
            fromUuid = value;
            OnPropertyChanged(nameof(FromUuid));
        }
    }
}
private string? fromUuid;

Regression

No response

Steps to reproduce

See description above. Use source-generation based serialization rather than reflection.

Expected behavior

I would expect it to deserialize. Not sure if it's Mvvm issue or System.Text.Json. But reported it here.

Screenshots

No response

IDE and version

VS 2022

IDE version

No response

Nuget packages

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.2.2

Additional context

Probably serialization also doesn't work.

Help us help you

No, just wanted to report this

Metadata

Metadata

Assignees

No one assigned

    Labels

    analyzer 👓A new analyzer being implemented or updatedby designSome behavior that is intended and not an issuemvvm-toolkit 🧰Issues/PRs for the MVVM Toolkit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions