Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static class SimplePageImpl<T> implements Page<T> {
private final Page<T> delegate;

SimplePageImpl(@JsonProperty("content") List<T> content,
@JsonProperty("page") int number, @JsonProperty("size") int size,
@JsonProperty("number") int number, @JsonProperty("size") int size,
@JsonProperty("totalElements") long totalElements) {
delegate = new PageImpl<>(content, PageRequest.of(number, size),
totalElements);
Expand All @@ -82,7 +82,7 @@ public long getTotalElements() {
return delegate.getTotalElements();
}

@JsonProperty("page")
@JsonProperty
@Override
public int getNumber() {
return delegate.getNumber();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2013-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.openfeign.support;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import org.springframework.data.domain.Page;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Ruben Vervaeke
*/
public class PageJacksonModuleTests {

private static ObjectMapper objectMapper;

@BeforeAll
public static void initialize() {
objectMapper = new ObjectMapper();
objectMapper.registerModule(new PageJacksonModule());
}

@Test
public void deserializePage() throws JsonProcessingException {
// Given
String pageJson = "{\"content\":[\"A name\"], \"number\":1, \"size\":2, \"totalElements\": 3}";
// When
Page<?> result = objectMapper.readValue(pageJson, Page.class);
// Then
assertThat(result).isNotNull();
assertThat(result.getTotalElements()).isEqualTo(3);
assertThat(result.getContent()).hasSize(1);
assertThat(result.getPageable()).isNotNull();
assertThat(result.getPageable().getPageSize()).isEqualTo(2);
assertThat(result.getPageable().getPageNumber()).isEqualTo(1);
}

}