Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
JsonSerializer.Deserialize won't work in class C#

I am trying everything I can but the object is not getting deserialized, I tried almost all the possible solutions to the problem but nothing is working, if someone can help that would be great. please see below is the code snippet for the code it always returns a null value to me.

using System;
using System.Text.Json;

namespace ConsoleApp8
{
    class Program
    {

        static void Main(string[] args)
        {
            var a = "{\"enrollmentType\":\"draft\",\"emrName\":\"accuro\",\"emrVersion\":\"v1\",\"workflowType\":\"coordinator\"}";
            var x = "{\"enrollmentType\":\"draft\",\"emrName\":\"accuro\",\"emrVersion\":\"v1\",\"workflowType\":\"coordinator\"}";
            string json = @"{""id"":10,""name"":""Name"",""revisionDate"":1390293827000}";

            
            var ed = JsonSerializer.Deserialize<EnrollmentExtension>(x);
            //.Replace("'", "\"")
            if (!string.IsNullOrWhiteSpace(ed.emrName))
            { }
        }
    }
    public class EnrollmentExtension
        {
            #region MyRegion
            private string _emrName;
            private string _emrVersion;
            private string _workflowType;
            private string _enrollmentType; public bool IsDraft()
            {
                return (string.Compare(_enrollmentType, "draft", true) == 0);
            }
        #endregion

            
            public string enrollmentType
            {
                get { return _enrollmentType; }
                private set { _enrollmentType = value; }
            }
            public string workflowType
            {
                get { return _workflowType; }
                private set { _workflowType = value; }
            }
            public string emrVersion
            {
                get { return _emrVersion; }
                private set { _emrVersion = value; }
            }
            public string emrName
            {
                get { return _emrName; }
                private set { _emrName = value; }
            }
            public void SetWorkflowType(string workFlowType)
            {
                _workflowType = workFlowType;
            }
        }
        public class Test
        {
            public EnrollmentExtension myprop { get; set; }
        }
    }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

you have a bug in your classes, all your setters are private, but they should be public. all properties should be like this

 public string enrollmentType { get { return _enrollmentType; } set { _enrollmentType = value; } }

or you can keep the setters private but create a constructor

 public EnrollmentExtension(string enrollmentType, ... and so on, string workflowType) { _enrollmentType=enrollmentType; _workflowType=workflowType; ... and so on }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!