Spring 启动 - 休息分页 return 消息 HttpMessageNotWritableException

Spring boot - Rest Pagination return message HttpMessageNotWritableException

我尝试使用 Spring Boot 1.5.3 和 Elasticsearch 为我的 api 实现分页,但它 return 出现了 HttpMessageNotWritableException: 无法写入 JSON 文档。

我认为 ElasticsearchRepository 已经提供了分页和排序方法,所以我尝试将 return 可分页对象用于我的控制器。而且我认为错误发生在控制器 returns 结果时。

这是控制器。

@GetMapping(value = "/client",
            params = { "page", "size" })
public Page<Client> getAllClient( @RequestParam("page") int page, @RequestParam("size") int size){
    return clientService.getAllClient(page, size);
}

服务。

public Page<Client> getAllClient(int page, int size) {
    Page<Client> resultPage = clientRepository.findAll(new PageRequest(0, 3));
    return resultPage;
}

存储库。

public interface ClientRepository extends 
ElasticsearchRepository<Client, String> {
    public Client findByName(String name);
}

我已经将 Lombok 用于我的实体,所以这应该不是问题。

@Data
@Document(indexName = "customer", type = "client")
public class Client {

    @Id
    private String id;

    private String name;

    private String city;

    private String phone;
}

pom.xml

中的依赖项
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.8</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

当我向与控制器映射的 url 发出 HTTP GET 请求时,出现以下错误日志。

WARN 12616 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON document: (was java.lang.NullPointerException) (through reference chain: org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl["facets"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl["facets"])

我想知道我是否忘记了我的项目中的任何配置。

我刚发现我改成Spring Boot version 2.0.4后就可以了!

但我还是想知道在 1.5.3 版本中如何实现。