0

I'm attempting to deserialize the following json:

{"PatientNameID":{"ID":514,"Name":{"First":"Laura","Middle":"X","Last":"Coelho","Suffix":"","Full":"Laura X Coelho","Preferred":""}},"PatientNumber":"254","ChartNumber":"254","Gender":{"LookupType":"Gender","Code":"F","Description":"Female","Order":1,"Active":true,"AlternateCodes":null},"DOB":"4/9/1953","PhoneNumber":"3521029496","SSN":"*****0161"}

This is the class and subclasses into which I'm trying to deserialize the above JSON:

public class PatientList3
{
    public Pat PatientNameID { get; set; }
    public string PatientNumber { get; set; }
    public string ChartNumber { get; set; }
    public Gender2 Gender { get; set; }
    public string DOB { get; set; }
    public string PhoneNumber { get; set; }
    public string SSN { get; set; }
}

public class Pat
{
    public int ID { get; set; }
    public PtName Name { get; set; }
}

public class PtName
{
    public string First { get; set; }
    public string Middle { get; set; }
    public string Last { get; set; }
    public string Suffix { get; set; }
    public string Full { get; set; }
    public string Preferred { get; set; }
}

public class Gender2
{
    string LookupType { get; set; }
    string Code { get; set; }
    string Description { get; set; }
    int Order { get; set; }
    bool Active { get; set; }
    List<AlternateCodes> AlternateCodes { get; set; }
}

public class AlternateCodes
{
    string Code { get; set; }
    string Description { get; set; }
    string CodeSystem { get; set; }
    string CodeSystemName { get; set; }
}

Everything goes well when I deserialize it except all of the values in the Gender2 class are null.

I've referred to the following two posts for answers but nothing seems to be doing to trick.

3
  • 1
    Fix the properties that are not public! Commented Feb 22, 2018 at 16:25
  • @cleftheris thanks, feel pretty dumb over looking that. Commented Feb 22, 2018 at 16:33
  • @w-harr glad it worked out. Commented Feb 22, 2018 at 16:34

2 Answers 2

3

Fix the properties on Gender2 & AlternateCodes they are not public! The deserializer will not be able to find your any of your properties so that is probably the reason this fails to populate.

Sign up to request clarification or add additional context in comments.

Comments

1

The problem is with access modifiers of properties Gender2 and AlternateCodes class, default access modifiers for properties is private. You should change it to:

public class Gender2
{
    public string LookupType { get; set; }
    public string Code { get; set; }
    public string Description { get; set; }
    public int Order { get; set; }
    public bool Active { get; set; }
    public List<AlternateCodes> AlternateCodes { get; set; }
}

public class AlternateCodes
{
    public string Code { get; set; }
    public string Description { get; set; }
    public string CodeSystem { get; set; }
    public string CodeSystemName { get; set; }
}

After setting properties to public it deserializes successfully:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.