报错信息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)
这种情况出现在反序列化对象的嵌套对象没有默认构造函数时.