我有这样的方法:
public List<CustomerDTO> getAllCustomers() {
Iterable<Customer> customer = customerRepository.findAll();
ObjectMapper mapper = new ObjectMapper();
return (List<CustomerDTO>) mapper.convertValue(customer, CustomerDTO.class);
}
当我尝试转换
List
值时,出现以下消息com.fasterxml.jackson.databind.JsonMappingException:无法从START_ARRAY令牌中反序列化com.finman.customer.CustomerDTO实例
最佳答案
mapper.convertValue(customer, CustomerDTO.class)
这将尝试创建单个
CustomerDTO
,而不是它们的列表。也许这会有所帮助:
mapper.readValues(customer, CustomerDTO.class).readAll()