title: Parsing dynamic JSON values to Java objects
body: <p>In my application I have lot of overviews (tables) with sorting and filtering capabilities. And becuase the different column can hold different value type (strings, numbers, dates, sets, etc.) the filter for these columns also can bring different values. Let me show you few examples (converted to JSON already as is sent to server via REST request):</p>
  
  <p>For simple string value it is like:</p>
  
  <pre><code>{"&lt;column_name&gt;":"&lt;value&gt;"}
  </code></pre>
  
  <p>For number and date column the filter looks like:</p>
  
  <pre><code>{"&lt;column_name&gt;":[{"operator":"eq","value":"&lt;value&gt;"}]}
  {"&lt;column_name&gt;":[{"operator":"eq","value":"&lt;value1&gt;"},{"operator":"gt","value":"&lt;value2&gt;"}]}
  </code></pre>
  
  <p>For set the filter looks like</p>
  
  <pre><code>{"&lt;column_name&gt;":["&lt;value1&gt;","&lt;value2&gt;"(,...)]}
  </code></pre>
  
  <p>Now I need to parse that JSON within a helper class that will build the <code>WHERE</code> clause of SQL query. In PHP this is not a problem as I can call <code>json_decode</code> and then simply check whether some value is <code>array</code>, <code>string</code> or whatever else... But how to do this simply in Java?</p>
  
  <p>So far I am using Spring's <code>JsonJsonParser</code> (I didn't find any visible difference between different parsers coming with Spring like <code>Jackson</code>, <code>Gson</code> and others).</p>
  
  <p>I was thinking about creating an own data object class with three different constructors or having three data object classes for all of the three possibilities, but yet I have no clue how to deal with the <em>value</em> returned for <code>column_name</code> after the JSON is parsed by parser...</p>
  
  <p>Simply looking on the examples it gives me three possibilities:</p>
  
  <ol>
  <li><code>Map&lt;String, String&gt;</code></li>
  <li><code>Map&lt;String, Map&lt;String, String&gt;&gt;</code></li>
  <li><code>Map&lt;String, String[]&gt;</code></li>
  </ol>
  
  <p>Any idea or clue?</p>