Spring Data Couchbase - map dynamic keys in a JSON document to a model class

Is there a way to map dynamic keys in a JSON document to a model class and eventually read and write this document to a Couchbase bucket using Spring Data?
One approach would be to encapsulate all dynamic fields within a key, e.g., “data”, in the document. However, are there other options or best practices for managing such dynamic structures in Couchbase with Spring Data? Any guidance would be highly appreciated.

{
  "myDynamicKey1": [
    1,
    2,
    3
  ],
  "myDynamicKey2": true,
  "myDynamicKey3": null,
  "myDynamicKey4": 123,
  "myDynamicKey5": {
    "a": "b",
    "c": "d",
    "e": "f"
  },
  "myDynamicKey6": "Hello World"
}

I think your proposed approach - an enclosing object ‘data’ which would be a JsonObject’ is the best solution. A HashMap<String,String> would work if all the values were a single concrete type such as String. But given they are String, boolean, Number, Array - that won’t work. And HashMap<String,Object> will not work because spring data doesn’t know how to create an Object from arbitrary values.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.