【发布时间】:2023-01-24 07:19:52
【问题描述】:
使用 spring-data-couchbase 我想定义一个带有字段 settings 和通用 JSON 的文档。为此,我创建了一个类
@Document
public class SampleDoc {
@Id
@NotNull
protected String id;
@Field
private JsonNode settings;
}
当我尝试将 JSON 对象下面的内容保存到此文档实例时
{
"someField" : "someData"
}
它在 CouchBase 中保存为
"settings": {
"_children": {
"someField": {
"type": "com.fasterxml.jackson.databind.node.TextNode",
"_value": "someData"
}
},
"type": "com.fasterxml.jackson.databind.node.ObjectNode",
"_nodeFactory": {
"_cfgBigDecimalExact": false
}
}
当我尝试通过 CouchbaseRepository.findById 从数据库中获取文档时,它返回错误:
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
我如何将通用 JSON 对象持久保存到 Couchbase 并确保将其存储为简单的 JSON,例如:
{
//other fields
"settings" : {
"someField" : "someData"
}
//other fields
}
谢谢
【问题讨论】:
标签: java json spring-data couchbase spring-data-couchbase