JsonMappingException when testing endpoints with Pageable field

前端 未结 1 1187
名媛妹妹
名媛妹妹 2021-01-05 02:58

I need to call an endpoint which expects a Pageable field:

@GetMapping
public Page listProducts(Pageable pageable) {
    retur         


        
相关标签:
1条回答
  • 2021-01-05 03:15
    package com.td.support;
    
    import com.fasterxml.jackson.annotation.JsonCreator;
    import com.fasterxml.jackson.annotation.JsonProperty;
    import com.fasterxml.jackson.databind.JsonNode;
    import org.springframework.data.domain.PageImpl;
    import org.springframework.data.domain.PageRequest;
    import org.springframework.data.domain.Pageable;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class RestResponsePage<T> extends PageImpl<T> {
        @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
        public RestResponsePage(@JsonProperty("content") List<T> content,
                            @JsonProperty("number") int number,
                            @JsonProperty("size") int size,
                            @JsonProperty("totalElements") Long totalElements,
                            @JsonProperty("pageable") JsonNode pageable,
                            @JsonProperty("last") boolean last,
                            @JsonProperty("totalPages") int totalPages,
                            @JsonProperty("sort") JsonNode sort,
                            @JsonProperty("first") boolean first,
                            @JsonProperty("numberOfElements") int numberOfElements) {
    
            super(content, PageRequest.of(number, size), totalElements);
        }
    
        public RestResponsePage(List<T> content, Pageable pageable, long total) {
            super(content, pageable, total);
        }
    
        public RestResponsePage(List<T> content) {
            super(content);
        }
    
        public RestResponsePage() {
            super(new ArrayList<>());
        }
    }
    

    spring boot 2.0 may be ok above..

    0 讨论(0)
提交回复
热议问题