Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Deserialization issue - object returned unset #245

Open
isabr85 opened this issue Dec 28, 2020 · 1 comment
Open

Deserialization issue - object returned unset #245

isabr85 opened this issue Dec 28, 2020 · 1 comment

Comments

@isabr85
Copy link

isabr85 commented Dec 28, 2020

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?

@tomsoftware
Copy link

tomsoftware commented Apr 8, 2021

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);

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

No branches or pull requests

2 participants