Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Json serializer ignored properties #236

Closed
k3z0 opened this issue Feb 5, 2020 · 2 comments
Closed

Error Json serializer ignored properties #236

k3z0 opened this issue Feb 5, 2020 · 2 comments
Assignees
Labels

Comments

@k3z0
Copy link
Contributor

k3z0 commented Feb 5, 2020

Describe the bug
When you use JsonPropertyAttribute to ignore some properties, properties of inner objects with the same name are ignored too.

To Reproduce
Create the next set of classes:

public class User
{
    [JsonProperty(nameof(Id), true)]
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    public Address MainAddress { get; set; }
}

public class Address
{
    public int Id { get; set; }
    public string AddressLine1 { get; set; }
    public string AddressLine2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
}

Create a new instance of User:

var user = new User
{
	Id = 1,
	Name = "Simio Perez",
	Age = 42,
	MainAddress = new Address
	{
		Id = 123,
		AddressLine1 = "456 Apes Street",
		City = "Agartha",
		State = "Earth's core",
	},
};

Serialize the created user object using Json.Serialize:

var result = Json.Serialize(user);

You will get the next Json string:

{
    "Name": "Simio Perez",
    "Age": 42,
    "MainAddress": {
        "AddressLine1": "456 Apes Street",
        "AddressLine2": null,
        "City": "Agartha",
        "State": "Earth's core"
    }
}

The Id property not only was ignored from the User object but also from the inner Address object.

@geoperez geoperez self-assigned this Feb 5, 2020
@geoperez geoperez added the bug label Feb 5, 2020
@stale
Copy link

stale bot commented Apr 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@geoperez
Copy link
Member

New version published, v3.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants