​​

报错信息

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of ​​com.cxyzy.note.server.bean.Note​​ (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

数据类

data class Note(
@BsonId val id: String = ObjectId.get().toString(),
var userId: String,
var title: String?,
var content: String?
) {
}

解决方案

给数据类增加默认构造函数

​constructor() : this(ObjectId.get().toString(), "", null, null)​

这种情况出现在反序列化对象的嵌套对象没有默认构造函数时.

jackson反序列号失败:com.fasterxml.jackson.databind.exc.InvalidDefinitionException_嵌套