org.springframework.data.elasticsearch.ElasticsearchException: failed to map source [ {“color”:“红色”,“price”:40000.0,“name”:“奔驰A4”,“id”:14}] to class Car
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of com.yzh.essupergo2.domain.Car
(no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
原因:
这是因为在实体类Item中为了方便实例化添加了一个有参构造函数,导致JVM不能添加默认的无参构造函数了,但是jackson的反序列化需要使用无参构造函数,所以报错!
解决:
在实体类Item中添加一个无参构造函数就可以了!