title: FHIR's General-Purpose Data Type Object Parsing From JSON in .NET Core
body: <p>I am using <a href="https://github.com/FirelyTeam/fhir-net-api/tree/develop-r4" rel="nofollow noreferrer">Hl7.Fhir.R4</a> library in my project which is an API Wrapper (in ASP.NET Core 2.2) around <a href="https://github.com/microsoft/fhir-server" rel="nofollow noreferrer">Azure API for FHIR</a>.
  In a View Model, I declared a FHIR Element (<a href="https://www.hl7.org/fhir/datatypes.html" rel="nofollow noreferrer">FHIR's General-Purpose Data Type</a>) as a property. Example:</p>
  
  <pre><code>public class MyPatient
  {
      public string Name { get; set;}
      public Hl7.Fhir.Model.CodeableConcept MaritalStatus { get; set;} //This is 
                                                            //defined in the library
  } 
  </code></pre>
  
  <p>Now, the <strong>problem</strong> is: The 'MaritalStatus' is not being parsed from json to the c# object (<a href="https://github.com/FirelyTeam/fhir-net-api/blob/develop-r4/src/Hl7.Fhir.Core/Model/Generated/CodeableConcept.cs" rel="nofollow noreferrer">defined in the library</a>), properly (i.e it is just 'not null'). Neither is there any exception being thrown.</p>
  
  <p><strong>Explained With Details:</strong>
  This is the JSON I am receiving from the front-end:</p>
  
  <pre><code> { 
     "name": "TheName", 
     "maritalStatus": {
        "coding": [ 
           { 
             "system": "terminology.hl7.org/CodeSystem/v3-MaritalStatus", 
             "code": "U", 
             "display": "unmarried"
           } 
         ], 
        "text": "Unmarried" 
      } 
  }
  
  </code></pre>
  
  <p>This is my model (C# class) against the JSON I am receiving from the front-end:</p>
  
  <pre><code>public class MyPatient
  {
      public string Name { get; set;}
      public Hl7.Fhir.Model.CodeableConcept MaritalStatus { get; set;}
  } 
  </code></pre>
  
  <p>This the controller's action (in the wrapper layer - my project) which is entertaining the request:</p>
  
  <pre><code>        [HttpPut("{id}")]
          [Consumes("application/json")]
          [Produces("application/json")]
          public async Task&lt;ActionResult&gt; Update([Required][FromRoute] string id,[Required][FromBody] MyPatient myPatient)
          {
              if (ModelState.IsValid)
              {
  
                 Hl7.Fhir.Model.Patient patient = await _fhirClient.ReadAsync&lt;Patient&gt;(location: "Patient/" + id);
  
                 patient.MaritalStatus = myPatient.MaritalStatus;
  
                 patient.Name[0].Text = myPatient.Name;
  
                 patient = await _fhirClient.UpdateAsync&lt;Patient&gt;(patient);
  
                 return Ok();
  
              }//ends If ModelState.IsValid
  
              return BadRequest();
          }//ends Update
  </code></pre>