illegalargumentexception:无法反序列化的示例

az31mfrm  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(564)

我有一个spring-boot应用程序,其中有一个blogsservice调用blogs存储库,它应该返回一个与所传递的搜索查询匹配的blog列表。我得到以下是由第76行引起的。有什么想法吗?谢谢
第76行:

return objectMapper.convertValue(searchEntity, BlogDetailsResponse.class);

illegalargumentexception:无法反序列化的示例 package.dto.BlogDetailsResponse 在[源:未知;行:-1,列:-1]位于com.cor.devsquareawsservice.services.impl.blogserviceimpl.searchblogs(blogserviceimpl。java:76)~[类/: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);
    }
  }

博客存储.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;
  }
2fjabf4q

2fjabf4q1#

这解决了我的问题。我需要绘制名单并隐藏每个实体。

public List<BlogDetailsResponse> searchBlogs(SearchBlogsRequest searchBlogsRequest) {
    try {
      return blogsRepository.searchBlogs(searchBlogsRequest.getSearchBlogsQuery()).stream().map(e -> objectMapper
              .convertValue(e, BlogDetailsResponse.class))
              .collect(Collectors.toList());
    } catch (final Exception exception) {
      log.error(exception);
      throw new DevSquareDynamoDBException(ExceptionConstants.SERVICE_SEARCH_BLOGS_EXCEPTION_MESSAGE, exception);
    }
  }

相关问题