Upsert Document with a generic json field

Using spring-data-couchbase I want to define a document with a field settings with generic JSON. To do this, I create a class

@Document
public class SampleDoc {
  @Id
  @NotNull
  protected String id;

  @Field
  private JsonNode settings;
}

When I try to persist below JSON object to this document instance

{
  "someField" : "someData"
}

It is persisted in the CouchBase as

"settings": {
    "_children": {
      "someField": {
        "type": "com.fasterxml.jackson.databind.node.TextNode",
        "_value": "someData"
      }
    },
    "type": "com.fasterxml.jackson.databind.node.ObjectNode",
    "_nodeFactory": {
      "_cfgBigDecimalExact": false
    }
  }

And when I try to get the document from database through CouchbaseRepository.findById it returns error :

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate com.fasterxml.jackson.databind.node.ObjectNode using constructor NO_CONSTRUCTOR with arguments ] with root cause

How could I persist a generic JSON object to Couchbase and assure it to be stored as a simple JSON like :

{
  //other fields
  "settings" : {
    "someField" : "someData"
  }
  //other fields
}

Thank you

You can define the following converters to convert a JsonNode to/from a CouchbaseDocument and register their INSTANCE as CouchbaseCustomConversions. If you would like this converter provided in spring-data-couchbase, please open an issue at Issues · spring-projects/spring-data-couchbase · GitHub

@WritingConverter
public enum JsonNodeToMap implements Converter<JsonNode, CouchbaseDocument> {
	INSTANCE;

	@Override
	public CouchbaseDocument convert(JsonNode source) {
		if( source == null ){
			return null;
		}
		return new CouchbaseDocument().setContent(JsonObject.fromJson(source.toString()));
	}
}


@ReadingConverter
public enum MapToJsonNode implements Converter<CouchbaseDocument, JsonNode> {
	INSTANCE;
	static ObjectMapper mapper= new ObjectMapper();
	
	@Override
	public JsonNode convert(CouchbaseDocument source) {
		if( source == null ){
			return null;
		}
		return mapper.valueToTree(source.export());
	}
}