title: How to know from Json which class an object is in SpringBoot?
body: <p>I have the following JSON object in the body of a request:</p>
  <p><strong>JSON</strong></p>
  <pre><code>{
      &quot;nombre&quot;: &quot;example&quot;,
      &quot;number&quot;: 100,
      &quot;listOfMeasurables&quot;:{
            &quot;measurableOne&quot;:{
                &quot;positionOne&quot;:[0,3,0],
                &quot;positionTwo&quot;:[0,3,0]
            },
            &quot;measurableTwo&quot;:{
                &quot;positionOne&quot;:[0,3]
            }
      }
  }
  </code></pre>
  <p>Now i have Class Measurable which is Abstract, and MeasurableOne, MeasurableTwo, and MeasurableThree, which extends Measurable.</p>
  <p><strong>Measurable</strong></p>
  <pre><code>public abstract class Measurable {
      public abstract String getType();
      
  }
  </code></pre>
  <p><strong>MeasurableOne</strong></p>
  <pre><code>public class MeasurableOne extends Measurable {
      protected int [] positionOne;
      protected int [] positionTwo;
      
      public MeasurableOne(int [] positionOne, int [] positionTwo) {
          this.positionOne = positionOne;
          this.positionTwo = positionTwo;
      }
      
      @Override
      public String getType() {
          return &quot;MeasurableOne&quot;;
      }
  }
  </code></pre>
  <p><strong>MeasurableTwo</strong></p>
  <pre><code>public class MeasurableTwo extends Measurable {
      protected int [] positionOne;
      
      public MeasurableTwo(int [] positionOne) {
          this.positionOne = positionOne;
      }
      
      @Override
      public String getType() {
          return &quot;MeasurableTwo&quot;;
      }
  }
  </code></pre>
  <p><strong>MeasurableThree</strong></p>
  <pre><code>public class MeasurableThree extends Measurable {
      protected int [] positionOne;
      protected int [] positionTwo;
      protected int [] positionThree;
      
      public MeasurableThree(int [] positionOne, int [] positionTwo, int [] positionThree) {
          this.positionOne = positionOne;
          this.positionTwo = positionTwo;
          this.positionThree = positionThree;
      }
      
      @Override
      public String getType() {
          return &quot;MeasurableThree&quot;;
      }
  }
  </code></pre>
  <p>Now, i have a controller, which will receive this json. The listOfMeasurables array, can contain either measurableOne, measurableTwo, measurableThree, 1, 2 or 3 of them, in any order. How can i make the controller know which type the measurables be in order to create that object?</p>
  <pre><code>@PostMapping(path = &quot;/createActivity&quot;)
      public ResponseEntity&lt;String&gt; createActivity(@RequestBody Activity activity) { -&gt;&gt; HERE
          
      }
  </code></pre>
  <p>Any help is appreciated! Thanks</p>