0

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; }
        }
    }
Serge
  • 40,935
  • 4
  • 18
  • 45
Russian Federation
  • 194
  • 1
  • 5
  • 24

1 Answers1

3

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

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

or you can keep the private setters but create a constructor

public  EnrollmentExtension(string enrollmentType, ... and so on,  string workflowType)
    {
        _enrollmentType=enrollmentType;
       _workflowType=workflowType;
      ... and so on
    }
Serge
  • 40,935
  • 4
  • 18
  • 45