【发布时间】:2021-03-09 19:13:07
【问题描述】:
我有一个 Spring Boot 应用程序,其中有一个 BlogsService 调用一个博客存储库,它应该返回一个与传递的搜索查询匹配的博客列表。我得到以下由第 76 行引起的。有什么想法吗?谢谢
第 76 行:
return objectMapper.convertValue(searchEntity, BlogDetailsResponse.class);
IllegalArgumentException:无法从 START_ARRAY 令牌中反序列化 package.dto.BlogDetailsResponse 的实例
在 [来源:未知;行:-1,列:-1]
在 com.cor.devsquareawsservice.services.impl.BlogServiceImpl.searchBlogs(BlogServiceImpl.java:76) ~[classes/:na]
BlogServiceImpl.java
@Override
public BlogDetailsResponse searchBlogs(SearchBlogsRequest searchBlogsRequest) {
try {
final List<BlogEntity> searchEntity = blogsRepository.searchBlogs(searchBlogsRequest.getSearchBlogsQuery());
return objectMapper.convertValue(searchEntity, BlogDetailsResponse.class);
} catch (final Exception exception) {
log.error(exception);
throw new DevSquareDynamoDBException(ExceptionConstants.SERVICE_CREATE_BLOG_EXCEPTION_MESSAGE, exception);
}
}
BlogsRepository.java
public List<BlogEntity> searchBlogs(String query) {
try {
DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
scanExpression.addFilterCondition("title", new Condition()
.withComparisonOperator(ComparisonOperator.CONTAINS)
.withAttributeValueList(new AttributeValue().withS(query)));
return dynamoDBMapper.scan(BlogEntity.class, scanExpression);
} catch (Exception ex) {
log.error("failed to get blogs > " + query);
}
return null;
}
【问题讨论】:
-
searchEntity 是 BlogEntity 的列表。 BlogDetailsResponse 不是一个列表,是一个对象。请提供有关 BlogDetailsResponse 代码和 BlogEntity 的更多详细信息。
标签: java spring amazon-web-services spring-boot amazon-dynamodb