Skip to content

Commit 2c2b9be

Browse files
committed
Fix Jackson custom locale with Joda Time test on Java 9
The translations for the timezone names vary between Java 8 and Java 9. For example, with Java 9, UTC's name is no longer localized while others have different localizations. This commit updates the test to verify that the correct locale is being used while also tolerating the different localization's of Java 8 and 9. See gh-7226
1 parent f396740 commit 2c2b9be

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -412,17 +412,19 @@ public void customTimeZoneFormattingADate() throws JsonProcessingException {
412412
}
413413

414414
@Test
415-
public void customLocale() throws JsonProcessingException {
416-
this.context.register(JacksonAutoConfiguration.class);
417-
TestPropertyValues.of("spring.jackson.locale:de").applyTo(this.context);
418-
TestPropertyValues.of("spring.jackson.date-format:zzzz").applyTo(this.context);
419-
this.context.refresh();
420-
ObjectMapper objectMapper = this.context
421-
.getBean(Jackson2ObjectMapperBuilder.class).build();
422-
423-
DateTime dateTime = new DateTime(1436966242231L, DateTimeZone.UTC);
424-
assertThat(objectMapper.writeValueAsString(dateTime))
425-
.isEqualTo("\"Koordinierte Universalzeit\"");
415+
public void customLocaleWithJodaTime() throws JsonProcessingException {
416+
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
417+
context.register(JacksonAutoConfiguration.class);
418+
TestPropertyValues
419+
.of("spring.jackson.locale:de_DE", "spring.jackson.date-format:zzzz",
420+
"spring.jackson.serialization.write-dates-with-zone-id:true")
421+
.applyTo(context);
422+
context.refresh();
423+
ObjectMapper objectMapper = context.getBean(ObjectMapper.class);
424+
DateTime jodaTime = new DateTime(1478424650000L,
425+
DateTimeZone.forID("Europe/Rome"));
426+
assertThat(objectMapper.writeValueAsString(jodaTime))
427+
.startsWith("\"Mitteleuropäische ");
426428
}
427429

428430
@Test

0 commit comments

Comments
 (0)