Java Can';t使用SpringDataCouchbase将JSON对象从Couchbase映射到DTO实体
我已经创建了一些数据模型对象来插入Couchbase并从中读取。它有简单的类型,2个字段是其他DTO对象Java Can';t使用SpringDataCouchbase将JSON对象从Couchbase映射到DTO实体,java,spring,couchbase,spring-data-couchbase,Java,Spring,Couchbase,Spring Data Couchbase,我已经创建了一些数据模型对象来插入Couchbase并从中读取。它有简单的类型,2个字段是其他DTO对象 @Data @AllArgsConstructor @Document public class Customer { @Id private int id; private String fullName; private String phoneNumber; private String address; private Dat
@Data
@AllArgsConstructor
@Document
public class Customer {
@Id
private int id;
private String fullName;
private String phoneNumber;
private String address;
private Date registrationDate;
private boolean isBusiness;
private String status;
private Tariff currentTariff;
private BillingAccount billingAccount;
}
所以,我用逻辑创建了10000个随机客户对象,然后它创建repository.saveAll(customers)
我可以在Couchbase UI中看到这些数据
但是,我想从Couchbase获取所有这些客户对象。这是我的密码
@GetMapping("/findAllCustomers")
public Iterable<Customer> getAll() {
return repository.findAll();
}
@GetMapping(“/findAllCustomers”)
公共Iterable getAll(){
返回repository.findAll();
}
非常简单,没有自定义转换,没有其他复杂的东西。我期望的类型正是我生成和保存此数据时使用的类型
我得到以下错误:
未能使用实例化com.bamber.boostr.model.Customer
constructor public com.bacher.boostr.model.Customer
原因:java.lang.ClassCastException:java.lang.String不能为
转换为java.lang.Integer\r\n\t
com.bacher.boostr.model.Customer_实例化器_z47nsm.newInstance(未知
源)\r\n\t
org.springframework.data.convert.ClassGeneratingTityInstantiator$EntityInstantiatorAdapter.createInstance(ClassGeneratingTityInstantiator.java:226)\r\n\t
请帮助我删除了@AllArgsConstructor Lombok注释,并创建了没有Id字段的构造函数
@Data
@Document
public class Customer {
@Id
@GeneratedValue(strategy = GenerationStrategy.UNIQUE)
private String id;
private String fullName;
private String phoneNumber;
private String address;
private Date registrationDate;
private boolean isBusiness;
private String status;
private Tariff currentTariff;
private BillingAccount billingAccount;
public Customer(String fullName, String phoneNumber, String address, Date registrationDate, boolean isBusiness, String status, Tariff currentTariff, BillingAccount billingAccount) {
this.fullName = fullName;
this.phoneNumber = phoneNumber;
this.address = address;
this.registrationDate = registrationDate;
this.isBusiness = isBusiness;
this.status = status;
this.currentTariff = currentTariff;
this.billingAccount = billingAccount;
}
}
在那之后,它工作得很好。读和写操作