Skip to content

Commit

Permalink
Merge branch '3.1.x'
Browse files Browse the repository at this point in the history
Closes gh-38220
  • Loading branch information
mhalbritter committed Nov 6, 2023
2 parents 4bc63b5 + 7829e76 commit 9fc3ef7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
Expand All @@ -36,6 +37,7 @@
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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -68,7 +69,33 @@ void deserializeToListWhenMultipleLines() {
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) {
}

}

0 comments on commit 9fc3ef7

Please sign in to comment.