未找到能够从类型[java.util.LinkedHashMap<;?,?>;]转换为类型[com.csc.gts.model.entity]的转换器
我目前正在做一个MongoDB+spring启动项目,在创建映射时遇到了一些问题。 在我的模型中,有一个类叫做AllocRequests:未找到能够从类型[java.util.LinkedHashMap<;?,?>;]转换为类型[com.csc.gts.model.entity]的转换器,java,spring,mongodb,spring-boot,Java,Spring,Mongodb,Spring Boot,我目前正在做一个MongoDB+spring启动项目,在创建映射时遇到了一些问题。 在我的模型中,有一个类叫做AllocRequests: 公共类AllocRequests{ @字段(“ShipmentAllocRequest”) 私人船舶许可证船舶许可证; 公共AllocRequests(){} 公共AllocRequests(ShipmentAllocRequest ShipmentAllocRequest){ this.shipmentAllocRequest=shipmentAllocR
公共类AllocRequests{
@字段(“ShipmentAllocRequest”)
私人船舶许可证船舶许可证;
公共AllocRequests(){}
公共AllocRequests(ShipmentAllocRequest ShipmentAllocRequest){
this.shipmentAllocRequest=shipmentAllocRequest;
}
公共ShipmentAllocRequest getShipmentAllocRequest(){
退货请求;
}
公共无效设置ShipmentAllocRequest(ShipmentAllocRequest ShipmentAllocRequest){
this.shipmentAllocRequest=shipmentAllocRequest;
}
}
但是当我运行代码时,我会得到'org.springframework.core.convert.ConverterNotFoundException:没有找到能够从类型[java.util.LinkedHashMap]转换为类型[com.csc.gts.model.ShipmentAllocRequest]的转换器'
问题在于数据的结构
我注意到一些“ShipmentAllocRequest”是一个对象:
而另一些可以是数组:
我已尝试将模型类更改为:
公共类AllocRequests{
@字段(“ShipmentAllocRequest”)
私有列表shipmentAllocRequest;
公共AllocRequests(){}
公共AllocRequests(列表shipmentAllocRequest){
this.shipmentAllocRequest=shipmentAllocRequest;
}
公共列表getShipmentAllocRequest(){
退货请求;
}
公共作废setShipmentAllocRequest(列表shipmentAllocRequest){
this.shipmentAllocRequest=shipmentAllocRequest;
}
}
但接下来我会遇到一个新问题:
org.springframework.beans.beans实例化异常:未能实例化[java.util.List]:指定的类是接口
有人能帮我解决这个问题吗?我有两个问题,你是如何将数据插入MongoDB的?你是如何获取数据的?@MarcosBarbero Hi Marcos,谢谢你询问背景故事。我首先得到一个JSON文件,然后编写一些脚本将这些JSON记录插入MongoDb