mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Merge branch '3.1.x'
Closes gh-38220
This commit is contained in:
commit
9fc3ef7c93
@ -18,6 +18,7 @@ package org.springframework.boot.docker.compose.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
@ -36,6 +37,7 @@ import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
||||
final class DockerJson {
|
||||
|
||||
private static final ObjectMapper objectMapper = JsonMapper.builder()
|
||||
.defaultLocale(Locale.ENGLISH)
|
||||
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
|
||||
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
|
||||
.addModule(new ParameterNamesModule())
|
||||
|
@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.docker.compose.core;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -68,7 +69,33 @@ class DockerJsonTests {
|
||||
assertThat(response).containsExactly(new TestResponse(1), new TestResponse(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBeLocaleAgnostic() {
|
||||
// Turkish locale lower cases the 'I' to a 'ı', not to an 'i'
|
||||
withLocale(Locale.forLanguageTag("tr-TR"), () -> {
|
||||
String json = """
|
||||
{ "INTEGER": 42 }
|
||||
""";
|
||||
TestLowercaseResponse response = DockerJson.deserialize(json, TestLowercaseResponse.class);
|
||||
assertThat(response.integer()).isEqualTo(42);
|
||||
});
|
||||
}
|
||||
|
||||
private void withLocale(Locale locale, Runnable runnable) {
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(locale);
|
||||
runnable.run();
|
||||
}
|
||||
finally {
|
||||
Locale.setDefault(defaultLocale);
|
||||
}
|
||||
}
|
||||
|
||||
record TestResponse(int value) {
|
||||
}
|
||||
|
||||
record TestLowercaseResponse(int integer) {
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user