neuecc/Utf8Json

Deserialization issue - object returned unset

isabr85 opened this issue · 1 comments

I have a class of Customer:

public class Customer
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int Age { get; set; }
        public string Address { get; set; }
        public Customer()
        {
            FirstName = "First Name Test";
            LastName = "Last Name Test";
            Age = 30;
            Address = "Neverland";
        }
    }

From swagger - json string received as camel case (firstName instead of FirstName in Customer class):
"{\"firstName\":\"myName\",\"lastName\":\"myLastName\",\"age\":0,\"address\":\"myAddress\"}"

Because of this difference, my Customer object in not set with the values and contains the default values from the constructor. Other serialization libraries can handle this scenario. Is there a solution in utf8json to handle camel-case string where my class contains pascal-case memers?

use attributes

[DataMember(Name = "firsName")]
public string FirstName { get; set; }

or you can set this option global by

// default serializer change to allow private/exclude null/snake_case serializer.
JsonSerializer.SetDefaultResolver(StandardResolver.SnakeCase);