Mapping数据类型的MappingException [英] MappingException for Map type of data

查看:160
本文介绍了Mapping数据类型的MappingException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将地图类型数据保存到ouchBase时,我遇到了异常

While saving Map type data in couchBase I am getting an exception

由以下原因引起:org.springframework.data.mapping.MappingException:找不到类型java.lang.Object的PersistentEntity!

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

我已经在DataModel中拍摄了一张地图

I've taken a map in DataModel

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

我找到了并进行了覆盖可以在对象类型为

I found this and override couchBase configuration to do customMapping in case of Object Type like

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"
         }
      ]
   }
}

例外

由以下原因引起:java.lang.IllegalArgumentException:基本类型不能为null!

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

我想这是因为数组.请让我知道我在做什么错.

I guess it is because of the array. Please let me know what I am doing wrong.

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

I am using spring-data-couchbase version 2.0.4.RELEASE.

推荐答案

hi,请使用下面的代码,其原因是类型为null,并且沙发床映射转换​​程序无法读取文档它一定是可行的.

hi please use below code, its because type is null and couchbase mapping convertor cant read document its must be work.

@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);
        }
    }
    

这篇关于Mapping数据类型的MappingException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆