Skip to content

Commit 9fc3ef7

Browse files
committed
Merge branch '3.1.x'
Closes gh-38220
2 parents 4bc63b5 + 7829e76 commit 9fc3ef7

File tree

2 files changed

+29
-0
lines changed
  • spring-boot-project/spring-boot-docker-compose/src

2 files changed

+29
-0
lines changed

spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/DockerJson.java

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.util.List;
21+
import java.util.Locale;
2122

2223
import com.fasterxml.jackson.databind.DeserializationFeature;
2324
import com.fasterxml.jackson.databind.JavaType;
@@ -36,6 +37,7 @@
3637
final class DockerJson {
3738

3839
private static final ObjectMapper objectMapper = JsonMapper.builder()
40+
.defaultLocale(Locale.ENGLISH)
3941
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
4042
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
4143
.addModule(new ParameterNamesModule())

spring-boot-project/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerJsonTests.java

+27
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.docker.compose.core;
1818

1919
import java.util.List;
20+
import java.util.Locale;
2021

2122
import org.junit.jupiter.api.Test;
2223

@@ -68,7 +69,33 @@ void deserializeToListWhenMultipleLines() {
6869
assertThat(response).containsExactly(new TestResponse(1), new TestResponse(2));
6970
}
7071

72+
@Test
73+
void shouldBeLocaleAgnostic() {
74+
// Turkish locale lower cases the 'I' to a 'ı', not to an 'i'
75+
withLocale(Locale.forLanguageTag("tr-TR"), () -> {
76+
String json = """
77+
{ "INTEGER": 42 }
78+
""";
79+
TestLowercaseResponse response = DockerJson.deserialize(json, TestLowercaseResponse.class);
80+
assertThat(response.integer()).isEqualTo(42);
81+
});
82+
}
83+
84+
private void withLocale(Locale locale, Runnable runnable) {
85+
Locale defaultLocale = Locale.getDefault();
86+
try {
87+
Locale.setDefault(locale);
88+
runnable.run();
89+
}
90+
finally {
91+
Locale.setDefault(defaultLocale);
92+
}
93+
}
94+
7195
record TestResponse(int value) {
7296
}
7397

98+
record TestLowercaseResponse(int integer) {
99+
}
100+
74101
}

0 commit comments

Comments
 (0)