title: Deserialise Enum From JSON String with Spaces
body: <p>I'll preface this with the fact that I'm trying to avoid using <code>Newtonsoft.Json</code> since, ostensibly, <code>System.Text.Json</code> is ready for prime-time in .NET 6.</p>
  <p>So I have two enums coming from an API and I want to deserialise them using this test method:</p>
  <pre class="lang-cs prettyprint-override"><code>[Theory]
  [ClassData(typeof(TestDataGenerator))]
  public void CanDeserialiseEnumsWithCustomJsonStrings(Enum expected, string jsonName)
  {
      jsonName.ShouldNotBeNullOrEmpty();
      ReadOnlySpan&lt;char&gt; json = $&quot;{{\&quot;TestEnum\&quot;:\&quot;{jsonName}\&quot;}}&quot;;
  
      Type constructed = typeof(TestEnumWrapper&lt;&gt;).MakeGenericType(expected.GetType());
          
      var res = JsonSerializer.Deserialize(json, constructed);
  
      constructed.GetProperty(&quot;TestEnum&quot;).GetValue(res).ShouldBe(expected);
  }
  
  private class TestEnumWrapper&lt;T&gt; where T: struct
  {
      public T TestEnum { get; set; }
  }
  </code></pre>
  <p>(Yes I know that this could be done with <code>JsonSerializer.Deserialize&lt;T&gt;()</code>, I want to be able to test many types with this test so I need the reflection AFAICT).</p>
  <p>The first one, works fine:</p>
  <pre class="lang-cs prettyprint-override"><code>[JsonConverter(typeof(JsonStringEnumConverter))]
  public enum RecordType
  {
          [JsonPropertyName(&quot;country&quot;)]
          Country = 1,
  
          [JsonPropertyName(&quot;destinationOrbit&quot;)]
          DestinationOrbit = 2,
  
          [JsonPropertyName(&quot;engine&quot;)]
          Engine = 3,
          //etc...
  
  }
  </code></pre>
  <p>The second one, fails on the deserialization, this seems to be due to the spaces in the names.</p>
  <pre class="lang-cs prettyprint-override"><code>[JsonConverter(typeof(JsonStringEnumConverter))]
  public enum ObjectClass
  {
      [JsonPropertyName(&quot;Rocket Body&quot;)]
      RocketBody,
      [JsonPropertyName(&quot;Rocket Debris&quot;)]
      RocketDebris,
      [JsonPropertyName(&quot;Rocket Fragmentation Debris&quot;)]
      RocketFragmentationDebris,
      [JsonPropertyName(&quot;Rocket Mission Related Object&quot;)]
      RocketMissionRelatedObject,
      //etc...
  }
  </code></pre>
  <p>The API is controlled by the European Space Agency, so somehow, I don't think I'll be able to persuade them to rationalise the response a bit more.</p>
  <p>Is there any way around this?</p>
  <hr />
  <p>Some have asked for an example of the JSON I'm trying to deserialise. I'm currently working on the Attributes part of this blob:</p>
  <pre><code>{
              &quot;type&quot;: &quot;object&quot;,
              &quot;attributes&quot;: {
                  &quot;shape&quot;: null,
                  &quot;xSectMin&quot;: null,
                  &quot;satno&quot;: null,
                  &quot;depth&quot;: null,
                  &quot;objectClass&quot;: &quot;Rocket Fragmentation Debris&quot;,
                  &quot;cosparId&quot;: null,
                  &quot;length&quot;: null,
                  &quot;height&quot;: null,
                  &quot;mass&quot;: null,
                  &quot;xSectMax&quot;: null,
                  &quot;vimpelId&quot;: 84303,
                  &quot;xSectAvg&quot;: null,
                  &quot;name&quot;: null
              },
              &quot;relationships&quot;: {
                  &quot;states&quot;: {
                      &quot;links&quot;: {
                          &quot;self&quot;: &quot;/api/objects/61345/relationships/states&quot;,
                          &quot;related&quot;: &quot;/api/objects/61345/states&quot;
                      }
                  },
                  &quot;initialOrbits&quot;: {
                      &quot;links&quot;: {
                          &quot;self&quot;: &quot;/api/objects/61345/relationships/initial-orbits&quot;,
                          &quot;related&quot;: &quot;/api/objects/61345/initial-orbits&quot;
                      }
                  },
                  &quot;destinationOrbits&quot;: {
                      &quot;links&quot;: {
                          &quot;self&quot;: &quot;/api/objects/61345/relationships/destination-orbits&quot;,
                          &quot;related&quot;: &quot;/api/objects/61345/destination-orbits&quot;
                      }
                  },
                  &quot;operators&quot;: {
                      &quot;links&quot;: {
                          &quot;self&quot;: &quot;/api/objects/61345/relationships/operators&quot;,
                          &quot;related&quot;: &quot;/api/objects/61345/operators&quot;
                      }
                  },
                  &quot;launch&quot;: {
                      &quot;links&quot;: {
                          &quot;self&quot;: &quot;/api/objects/61345/relationships/launch&quot;,
                          &quot;related&quot;: &quot;/api/objects/61345/launch&quot;
                      }
                  },
                  &quot;reentry&quot;: {
                      &quot;links&quot;: {
                          &quot;self&quot;: &quot;/api/objects/61345/relationships/reentry&quot;,
                          &quot;related&quot;: &quot;/api/objects/61345/reentry&quot;
                      }
                  }
              },
              &quot;id&quot;: &quot;61345&quot;,
              &quot;links&quot;: {
                  &quot;self&quot;: &quot;/api/objects/61345&quot;
              }
          }
  </code></pre>