title: How to use @JsonProperty annotation with array containing elements of different format
body: <p>I'm using an API that uses in requests &amp; responses json array in a SpringBoot App with elements of various format and I'm struggling to dynamically get the right class to be used for serialisation/deserialisation of elements of such array.</p>
  <p>Here is a simplified description of the json:</p>
  <pre><code>{
      &quot;parameters&quot; :[
          {
              &quot;name&quot;: &quot;elementA&quot;,
              &quot;value&quot;: &quot;valueOfElementAsAString&quot;
          },
          {
              &quot;name&quot;: &quot;elementB&quot;,
              &quot;value&quot;: &quot;valueOfElementBAsString&quot;
          },
          {
              &quot;name&quot;: &quot;elementC&quot;,
              &quot;value&quot;: [
                  {
                      &quot;label&quot;:&quot;label1&quot;,
                      &quot;size&quot;:&quot;size1&quot;
                  },
                  {
                      &quot;label&quot;:&quot;label2&quot;,
                      &quot;size&quot;:&quot;size2&quot;
                  }
  
              ] 
          }
      ]
  }
  </code></pre>
  <p>Considering the following base classes:</p>
  <pre><code>class SimpleElement {
      @JsonProperty(&quot;name&quot;)
      public String name;
      @JsonProperty(&quot;value&quot;)
      public String value;
  
      //constructor &amp; stuff 
  }
  
  
  class ComplexElement {
      @JsonProperty(&quot;name&quot;)
      public String name;
      @JsonProperty(&quot;value&quot;)
      public ArrayList&lt;ComplexElementValue&gt; value = new ArrayList&lt;ComplexElementValue&gt;();
  
      //constructor &amp; stuff 
  }
  
  class ComplexElementValue {
      @JsonProperty(&quot;label&quot;)
      public String label;
      @JsonProperty(&quot;size&quot;)
      public String size;  
  
      //constructor &amp; stuff   
  }
  </code></pre>
  <p>Serialization/Deserialisation of individual Simple or Complex Elements works fine but how shall I declare my class Parameters using @JsonProperty to get the full array correctly handled ?:</p>
  <pre><code>class Parameters {
      ???
  }
  </code></pre>
  <p>Based on what I read, I've got the impression I have to write custom deserialiser &amp; serialiser but before doing so I would like to make sure there is no simpler way ?</p>
  <p>At the moment, considering I've got n x simpleElements and 1 x complexElement, I get it to work with such a class:</p>
  <pre><code>class Parameter {
     @JsonProperty(&quot;parameters&quot;)
     public MultiElement element;
  
     public class MultiElement {
        public ArrayList&lt;SimpleElement&gt; regularElements;
        public ComplexElement complexElement;
     }
    
     //constructor &amp; stuff 
  }
  </code></pre>
  <p>and handling the deserialisation/serialisation of the json &quot;manually&quot; using a JsonNode library (in this case org.camunda.spin.json.SpinJsonNode), but this sounds for me like a temporary solution</p>
  <p>Thanks in advance</p>