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