gpt4 book ai didi

couchbase - Map 类型数据的 MappingException

转载 作者:行者123 更新时间:2023-12-05 07:27:54 41 4
gpt4 key购买 nike

在 couchBase 中保存 Map 类型数据时出现异常

Caused by: org.springframework.data.mapping.MappingException: Couldn't find PersistentEntity for type java.lang.Object!

我在 DataModel 中拍了一张 map

@Data
public class test {
private Map<String,Object> testMap;
}

我找到了 this并覆盖 couchBase 配置以在对象类型的情况下执行 customMapping

protected <R> R read(final TypeInformation<R> type, final CouchbaseDocument source,
final Object parent) {
if (Object.class == typeMapper.readType(source, type).getType()) {
return (R) source.export();
} else {
return super.read(type, source, parent);
}
}

它适用于像

这样的请求
{  
"dummyMap":{
"key1":"val1",
"key2":"val2"
}
}

但是失败了

{  
"dummyMap":{
"key1":"val1",
"key2":"val2",
"objects":[
{
"key1":"val1",
"key2":"val2"
}
]
}
}

有异常(exception)

Caused by: java.lang.IllegalArgumentException: Basic type must not be null!

我猜是因为数组。请让我知道我做错了什么。

我正在使用 spring-data-couchbase 版本 2.0.4.RELEASE。

最佳答案

您好,请使用下面的代码,因为类型为 null 并且 couchbase 映射转换器无法读取文档它一定是工作。

@Override
@SuppressWarnings("unchecked")
protected <R> R read(final TypeInformation<R> type, final CouchbaseDocument source, final Object parent) {
if (type == null)
return (R) source.export();
if (Object.class == typeMapper.readType(source, type).getType()) {
return (R) source.export();
} else {
return super.read(type, source, parent);
}
}

关于couchbase - Map 类型数据的 MappingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53705146/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com