title: Deserialize value that may be an array of strings or a constant string?
body: <p>I am deserializing some JSON using <a href="https://serde.rs/" rel="nofollow noreferrer">Serde</a>. I am having problems with a value that is usually an array of strings, but can also be the constant string <code>&quot;all&quot;</code>. Expressed in JSON-schema it looks like this:</p>
  <pre><code>{
      &quot;oneOf&quot;: [
          {
              &quot;const&quot;: &quot;all&quot; 
          },
          {
              &quot;type&quot;: &quot;array&quot;,
              &quot;items&quot;: {
                  &quot;type&quot;: &quot;string&quot;
              }
          }
      ]
  }
  </code></pre>
  <p>I want to serialize it into this enum:</p>
  <pre><code>enum MyList {
      List(Vec&lt;String&gt;),
      All
  }
  </code></pre>
  <p>Here are a few examples:</p>
  <pre><code>[&quot;foo&quot;, &quot;bar&quot;]  // Should be MyList::List
  &quot;all&quot;           // Should be MyList::All
  &quot;foo&quot;           // Should be an error!
  </code></pre>
  <p>The question is, how do I deserialize this enum using serde? None of the <a href="https://serde.rs/container-attrs.html" rel="nofollow noreferrer">container attributes</a> or <a href="https://serde.rs/variant-attrs.html" rel="nofollow noreferrer">variant attributes</a> seem to help. If need be, I may change the design of the enum. However, the structure of the JSON is beyond my control.</p>