Merge branch '3.1.x'

Closes gh-38220
This commit is contained in:
Moritz Halbritter 2023-11-06 08:45:06 +01:00
commit 9fc3ef7c93
2 changed files with 29 additions and 0 deletions

View File

@ -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())

View File

@ -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) {
}
}