Skip to content

The JSON value could not be converted - ObservableCollection<T> #389

Description

@Symbai

I cannot deserialize the following JSON to an ObservableCollection (required for WPF applications) but successfully deserialize it to a List. In such a case deserializing to an ObservableCollection should be possible as well?!

Exception:

{"The JSON value could not be converted to System.Collections.Generic.ICollection`1[WpfApp12.Testing+Foo]. Path: $.MyList | LineNumber: 1 | BytePositionInLine: 22."}

JSON:

{
	"MyList": [
		{
			"Name": "Paul"
		},
		{
			"Name": "Mike"
		}
	]
}

Fails:

public class Foo
{
    public ObservableCollection<FooMember> MyList { get; set; }
}
public class FooMember
{
    public string Name { get; set; }
}

Succeeds:

public class Foo
{
    public List<FooMember> MyList { get; set; }
}
public class FooMember
{
    public string Name { get; set; }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions