Skip to content

Commit 6b996e3

Browse files
committed
Merge branch '4.3.x'
2 parents 4094476 + 446f61f commit 6b996e3

6 files changed

Lines changed: 386 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ static class SimplePageable implements Pageable {
243243

244244
private final PageRequest delegate;
245245

246-
SimplePageable(@JsonProperty("pageNumber") int number, @JsonProperty("pageSize") int size,
246+
SimplePageable(
247+
@JsonProperty("pageNumber") @JsonAlias({ "page-number", "page_number", "pagenumber",
248+
"PageNumber" }) int number,
249+
@JsonProperty("pageSize") @JsonAlias({ "page-size", "page_size", "pagesize", "PageSize" }) int size,
247250
@JsonProperty("sort") Sort sort) {
248251
delegate = buildPageRequest(number, size, sort);
249252
}

spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/PageJacksonModuleTests.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,83 @@ void serializeAndDeserializeFilledMultipleCascade() {
189189
assertThat(cascadedResult.getPageable().getPageNumber()).isEqualTo(6);
190190
}
191191

192+
@Test
193+
void deserializePageableWithHyphenatedAlias() throws IOException {
194+
// Given
195+
ObjectMapper kebabObjectMapepr = objectMapper.copy();
196+
kebabObjectMapepr.setPropertyNamingStrategy(PropertyNamingStrategies.KEBAB_CASE);
197+
File file = new File("./src/test/resources/withPageableAliasHyphen.json");
198+
// When
199+
Page<?> result = kebabObjectMapepr.readValue(file, Page.class);
200+
// Then
201+
assertThat(result).isNotNull();
202+
assertThat(result.getTotalElements()).isEqualTo(15);
203+
assertThat(result.getContent()).hasSize(10);
204+
assertThat(result.getPageable()).isNotNull();
205+
assertThat(result.getPageable().getPageNumber()).isEqualTo(2);
206+
assertThat(result.getPageable().getPageSize()).isEqualTo(3);
207+
assertThat(result.getPageable().getSort().getOrderFor("firstName").getDirection())
208+
.isEqualTo(Sort.Direction.ASC);
209+
}
210+
211+
@Test
212+
void deserializePageableWithUnderscoreAlias() throws IOException {
213+
// Given
214+
ObjectMapper snakeCaseObjectMapper = objectMapper.copy();
215+
snakeCaseObjectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
216+
File file = new File("./src/test/resources/withPageableAliasUnderscore.json");
217+
218+
// When
219+
Page<?> result = snakeCaseObjectMapper.readValue(file, Page.class);
220+
// Then
221+
assertThat(result).isNotNull();
222+
assertThat(result.getTotalElements()).isEqualTo(10);
223+
assertThat(result.getContent()).hasSize(10);
224+
assertThat(result.getPageable()).isNotNull();
225+
assertThat(result.getPageable().getPageNumber()).isEqualTo(1);
226+
assertThat(result.getPageable().getPageSize()).isEqualTo(2);
227+
assertThat(result.getPageable().getSort().getOrderFor("lastName").getDirection())
228+
.isEqualTo(Sort.Direction.DESC);
229+
}
230+
231+
@Test
232+
void deserializePageableWithLowercaseAlias() throws IOException {
233+
// Given
234+
ObjectMapper lowerCaseObjectMapper = objectMapper.copy();
235+
lowerCaseObjectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.LOWER_CASE);
236+
237+
File file = new File("./src/test/resources/withPageableAliasLowercase.json");
238+
239+
// When
240+
Page<?> result = lowerCaseObjectMapper.readValue(file, Page.class);
241+
// Then
242+
assertThat(result).isNotNull();
243+
assertThat(result.getTotalElements()).isEqualTo(8);
244+
assertThat(result.getContent()).hasSize(10);
245+
assertThat(result.getPageable()).isNotNull();
246+
assertThat(result.getPageable().getPageNumber()).isEqualTo(0);
247+
assertThat(result.getPageable().getPageSize()).isEqualTo(4);
248+
assertThat(result.getPageable().getSort()).isEqualTo(Sort.unsorted());
249+
}
250+
251+
@Test
252+
void deserializePageableWithPascalCaseAlias() throws IOException {
253+
// Given
254+
ObjectMapper upperCamelCaseObjectMapper = objectMapper.copy();
255+
upperCamelCaseObjectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.UPPER_CAMEL_CASE);
256+
File file = new File("./src/test/resources/withPageableAliasPascalCase.json");
257+
258+
// When
259+
Page<?> result = upperCamelCaseObjectMapper.readValue(file, Page.class);
260+
// Then
261+
assertThat(result).isNotNull();
262+
assertThat(result.getTotalElements()).isEqualTo(20);
263+
assertThat(result.getContent()).hasSize(10);
264+
assertThat(result.getPageable()).isNotNull();
265+
assertThat(result.getPageable().getPageNumber()).isEqualTo(3);
266+
assertThat(result.getPageable().getPageSize()).isEqualTo(2);
267+
assertThat(result.getPageable().getSort().getOrderFor("firstName").getDirection())
268+
.isEqualTo(Sort.Direction.ASC);
269+
}
270+
192271
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"content": [
3+
{
4+
"id": 3,
5+
"lastName": "Williams",
6+
"firstName": "Thomas",
7+
"email": "w.t@my.domain.com"
8+
},
9+
{
10+
"id": 1,
11+
"lastName": "Smith",
12+
"firstName": "James",
13+
"email": "s.j@my.domain.com"
14+
},
15+
{
16+
"id": 11,
17+
"lastName": "Scott",
18+
"firstName": "Steven",
19+
"email": "s.s@my.domain.com"
20+
},
21+
{
22+
"id": 8,
23+
"lastName": "Rodriguez",
24+
"firstName": "Daniel",
25+
"email": "r.d@my.domain.com"
26+
},
27+
{
28+
"id": 9,
29+
"lastName": "Martinez",
30+
"firstName": "Robert",
31+
"email": "m.r@my.domain.com"
32+
},
33+
{
34+
"id": 5,
35+
"lastName": "Jones",
36+
"firstName": "James",
37+
"email": "j.j@my.domain.com"
38+
},
39+
{
40+
"id": 2,
41+
"lastName": "Johnson",
42+
"firstName": "Robert",
43+
"email": "j.r@my.domain.com"
44+
},
45+
{
46+
"id": 6,
47+
"lastName": "Garcia",
48+
"firstName": "William",
49+
"email": "g.w@my.domain.com"
50+
},
51+
{
52+
"id": 7,
53+
"lastName": "Davis",
54+
"firstName": "Richard",
55+
"email": "d.r@my.domain.com"
56+
},
57+
{
58+
"id": 4,
59+
"lastName": "Brown",
60+
"firstName": "Paul",
61+
"email": "b.p@my.domain.com"
62+
}
63+
],
64+
"pageable": {
65+
"page-number": 2,
66+
"page-size": 3,
67+
"sort": {
68+
"orders": [
69+
{
70+
"direction": "ASC",
71+
"property": "firstName"
72+
}
73+
]
74+
}
75+
},
76+
"totalElements": 15
77+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"content": [
3+
{
4+
"id": 3,
5+
"lastName": "Williams",
6+
"firstName": "Thomas",
7+
"email": "w.t@my.domain.com"
8+
},
9+
{
10+
"id": 1,
11+
"lastName": "Smith",
12+
"firstName": "James",
13+
"email": "s.j@my.domain.com"
14+
},
15+
{
16+
"id": 11,
17+
"lastName": "Scott",
18+
"firstName": "Steven",
19+
"email": "s.s@my.domain.com"
20+
},
21+
{
22+
"id": 8,
23+
"lastName": "Rodriguez",
24+
"firstName": "Daniel",
25+
"email": "r.d@my.domain.com"
26+
},
27+
{
28+
"id": 9,
29+
"lastName": "Martinez",
30+
"firstName": "Robert",
31+
"email": "m.r@my.domain.com"
32+
},
33+
{
34+
"id": 5,
35+
"lastName": "Jones",
36+
"firstName": "James",
37+
"email": "j.j@my.domain.com"
38+
},
39+
{
40+
"id": 2,
41+
"lastName": "Johnson",
42+
"firstName": "Robert",
43+
"email": "j.r@my.domain.com"
44+
},
45+
{
46+
"id": 6,
47+
"lastName": "Garcia",
48+
"firstName": "William",
49+
"email": "g.w@my.domain.com"
50+
},
51+
{
52+
"id": 7,
53+
"lastName": "Davis",
54+
"firstName": "Richard",
55+
"email": "d.r@my.domain.com"
56+
},
57+
{
58+
"id": 4,
59+
"lastName": "Brown",
60+
"firstName": "Paul",
61+
"email": "b.p@my.domain.com"
62+
}
63+
],
64+
"pageable": {
65+
"pagenumber": 0,
66+
"pagesize": 4,
67+
"sort": {
68+
"orders": []
69+
}
70+
},
71+
"totalElements": 8
72+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"content": [
3+
{
4+
"id": 3,
5+
"lastName": "Williams",
6+
"firstName": "Thomas",
7+
"email": "w.t@my.domain.com"
8+
},
9+
{
10+
"id": 1,
11+
"lastName": "Smith",
12+
"firstName": "James",
13+
"email": "s.j@my.domain.com"
14+
},
15+
{
16+
"id": 11,
17+
"lastName": "Scott",
18+
"firstName": "Steven",
19+
"email": "s.s@my.domain.com"
20+
},
21+
{
22+
"id": 8,
23+
"lastName": "Rodriguez",
24+
"firstName": "Daniel",
25+
"email": "r.d@my.domain.com"
26+
},
27+
{
28+
"id": 9,
29+
"lastName": "Martinez",
30+
"firstName": "Robert",
31+
"email": "m.r@my.domain.com"
32+
},
33+
{
34+
"id": 5,
35+
"lastName": "Jones",
36+
"firstName": "James",
37+
"email": "j.j@my.domain.com"
38+
},
39+
{
40+
"id": 2,
41+
"lastName": "Johnson",
42+
"firstName": "Robert",
43+
"email": "j.r@my.domain.com"
44+
},
45+
{
46+
"id": 6,
47+
"lastName": "Garcia",
48+
"firstName": "William",
49+
"email": "g.w@my.domain.com"
50+
},
51+
{
52+
"id": 7,
53+
"lastName": "Davis",
54+
"firstName": "Richard",
55+
"email": "d.r@my.domain.com"
56+
},
57+
{
58+
"id": 4,
59+
"lastName": "Brown",
60+
"firstName": "Paul",
61+
"email": "b.p@my.domain.com"
62+
}
63+
],
64+
"pageable": {
65+
"PageNumber": 3,
66+
"PageSize": 2,
67+
"sort": {
68+
"orders": [
69+
{
70+
"direction": "ASC",
71+
"property": "firstName"
72+
}
73+
]
74+
}
75+
},
76+
"totalElements": 20
77+
}

0 commit comments

Comments
 (0)