neuecc / Utf8Json

Definitely Fastest and Zero Allocation JSON Serializer for C#(NET, .NET Core, Unity, Xamarin).
MIT License
2.36k stars 267 forks source link

[Question] How to deserialize ignoring missing properties? #215

Closed rafaelvascc closed 4 years ago

rafaelvascc commented 4 years ago

Lets say i have a C# class like...

public class Person
{
    public string FirstName {get;set;}
    public string LastName {get;set;}
    public int? Age {get;set;}
}

and i'm trying to deserialize the following json...

{
    "firstName": "bob",
    "age": 30
}

What i get is an object with all properties as null. if it try to deserialize the following json...

{
    "firstName": "bob",
    "lastName ": "dylan",
    "age": 30
}

I get the correct object with all properties.

Is there any way to deserialize a json text populating all existing properties and ignore the missing ones (the same behavior as Newtonsoft.Json)? This is the only issue preventing us to fully replace Newtonsfot.Json with Utf8Json.

Thanks.

fcortese2 commented 2 years ago

@rafaelvascc You marked this as closed, did you manage to find a workaround? If so, would you mind sharing? Having same issue changing from Newtonsoft.Json to Utf8Json...