有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java IllegalArgumentException:无法反序列化的实例

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

第76行:

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

IllegalArgumentException:无法反序列化启动\u数组令牌之外的package.dto.BlogDetailsResponse实例 位于[来源:未知;行:-1,列:-1] 在com。cor.devsquareawsservice。服务。impl。BlogServiceImpl。searchBlogs(BlogServiceImpl.java:76)~[classes/:na]

BlogServiceImpl。爪哇

  @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。爪哇

  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;
  }

共 (1) 个答案

  1. # 1 楼答案

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

      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);
        }
      }