title: Spring Boot and RethinkDB save JSON of unknown structure
body: <p>I develop Spring REST API. One of its endpoints must receive JSONs of unknown structure. To be exact, all JSONs has common header, but the inner document differs:</p>
  
  <pre><code>{
    "receiveData": {
      "iBusData": {
        "requestUID": "11111111-2222-3333-4444-555555555555",
        "messageKind": "PublishedData",
        "sender": "ST-DELLIN-307",
        "senderDateTime": "2018-10-15T09:09:09",
        "typeName": "typeContractor",
        "currentSenderApplication": "GP",
        "objectUID": "09876543-rrrr-aaaa-nnnn-ddddddddddddd",
        "data": {
          "contractor": {
            "uid": "09876543-rrrr-aaaa-nnnn-ddddddddddddd",
            "name": "Test_Contractor",
            "marked": false,
            "code": "763764568763",
            "isGroup": false,
            "fullName": "Test_Contractor",
            "INN": "Test_Contractor",
            "personalIDKindName ": "Test_Contractor",
            "personalIDSeries": "7634",
            "personalIDNumber": "18-111111111",
            "contractorCategory": "Test_Contractor",
            "contractorOPF": "Test_Contractor",
            "federalCategory": "Test_Contractor",
            "regionalCategory": "Test_Contractor"
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>Payload of <code>data</code> field may be different. All this nested documents (<code>contractor</code> in the example above) need to be stored in JSON-oriented database <code>RethinkDB</code>.</p>
  
  <p>How to implement endpoint that cat receive JSONs with different structured in the <code>data</code> field? </p>
  
  <p>Now I thought up to parse all JSONs as HashMap:</p>
  
  <pre><code>public ResponseEntity&lt;?&gt; all(@RequestBody HashMap json)
  </code></pre>
  
  <p>split HashMap to header and document and to store in database. But there are some difficulties:</p>
  
  <ul>
  <li>I need to select stored documents in the same format that they comes to endpoint</li>
  <li>I need to compare nested documents using <code>SHA256</code> and update them in the database</li>
  <li>I need to add three custom fields to the document before storing in the database</li>
  </ul>
  
  <p>How to do all this?</p>