Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

270
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda