Skip to content

Commit dd91dcd

Browse files
rvervaekrvvaeke
andauthored
Use property 'number' in JSON Page representation instead of 'page' (#320)
Fixes gh-237 Co-authored-by: rvvaeke <ruben.vervaeke@liantis.be>
1 parent 397130a commit dd91dcd

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/PageJacksonModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static class SimplePageImpl<T> implements Page<T> {
6464
private final Page<T> delegate;
6565

6666
SimplePageImpl(@JsonProperty("content") List<T> content,
67-
@JsonProperty("page") int number, @JsonProperty("size") int size,
67+
@JsonProperty("number") int number, @JsonProperty("size") int size,
6868
@JsonProperty("totalElements") long totalElements) {
6969
delegate = new PageImpl<>(content, PageRequest.of(number, size),
7070
totalElements);
@@ -82,7 +82,7 @@ public long getTotalElements() {
8282
return delegate.getTotalElements();
8383
}
8484

85-
@JsonProperty("page")
85+
@JsonProperty
8686
@Override
8787
public int getNumber() {
8888
return delegate.getNumber();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.openfeign.support;
18+
19+
import com.fasterxml.jackson.core.JsonProcessingException;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import org.junit.jupiter.api.BeforeAll;
22+
import org.junit.jupiter.api.Test;
23+
24+
import org.springframework.data.domain.Page;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
/**
29+
* @author Ruben Vervaeke
30+
*/
31+
public class PageJacksonModuleTests {
32+
33+
private static ObjectMapper objectMapper;
34+
35+
@BeforeAll
36+
public static void initialize() {
37+
objectMapper = new ObjectMapper();
38+
objectMapper.registerModule(new PageJacksonModule());
39+
}
40+
41+
@Test
42+
public void deserializePage() throws JsonProcessingException {
43+
// Given
44+
String pageJson = "{\"content\":[\"A name\"], \"number\":1, \"size\":2, \"totalElements\": 3}";
45+
// When
46+
Page<?> result = objectMapper.readValue(pageJson, Page.class);
47+
// Then
48+
assertThat(result).isNotNull();
49+
assertThat(result.getTotalElements()).isEqualTo(3);
50+
assertThat(result.getContent()).hasSize(1);
51+
assertThat(result.getPageable()).isNotNull();
52+
assertThat(result.getPageable().getPageSize()).isEqualTo(2);
53+
assertThat(result.getPageable().getPageNumber()).isEqualTo(1);
54+
}
55+
56+
}

0 commit comments

Comments
 (0)