【问题标题】:Getting Failed to instantiate [java.nio.HeapByteBuffer]: No default constructor found while retrieving from Mongo无法实例化 [java.nio.HeapByteBuffer]:从 Mongo 检索时未找到默认构造函数
【发布时间】:2020-12-12 11:53:44
【问题描述】:

我有一个java类如下

@Data
@Document(collection="sample_collection")
public class sampleClass {
  private Instant createTime;
  private Object payLoad;
  // some more fields
}

payload对象可以是null,也可以是不同类的对象,可以包含byteBuffer类型的字段。

现在,在尝试将其作为文档保存到 Mongo 时,我没有遇到任何问题,但是在检索文档时,我得到了实例化异常(只要填充了有效负载对象并具有 byteBuffer 字段)

以下是异常详情:

org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate java.nio.HeapByteBuffer using constructor NO_CONSTRUCTOR with arguments 
at org.springframework.data.convert.ReflectionEntityInstantiator.createInstance
at org.springframework.data.convert.ClassGeneratingEntityInstantiator.createInstance
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read

我无法找到为 HeapByteBuffer 字段定义构造函数的方法。 任何线索将不胜感激。

【问题讨论】:

    标签: java spring mongodb reflection spring-data-mongodb


    【解决方案1】:

    在我看来,您应该在实体中使用更具体的类作为字段 或者 您可以尝试使用转换器作为此问题的解决方法: Setup custom converters in Spring Data Mongo

    【讨论】:

      猜你喜欢
      • 2016-10-29
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多