diff --git a/src/main/java/com/fasterxml/jackson/datatype/joda/cfg/JacksonJodaDateFormat.java b/src/main/java/com/fasterxml/jackson/datatype/joda/cfg/JacksonJodaDateFormat.java index 745a5ff..60ed3b4 100644 --- a/src/main/java/com/fasterxml/jackson/datatype/joda/cfg/JacksonJodaDateFormat.java +++ b/src/main/java/com/fasterxml/jackson/datatype/joda/cfg/JacksonJodaDateFormat.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.datatype.joda.cfg; import java.util.Locale; -import java.util.Objects; import java.util.TimeZone; import org.joda.time.DateTimeZone; diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/failing/DateTimeSerializationWithOffsets146Test.java b/src/test/java/com/fasterxml/jackson/datatype/joda/failing/DateTimeSerializationWithOffsets146Test.java index d1c129c..16ea91b 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/failing/DateTimeSerializationWithOffsets146Test.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/failing/DateTimeSerializationWithOffsets146Test.java @@ -10,22 +10,24 @@ // [datatype-joda#146]: disable overwriting of timezone public class DateTimeSerializationWithOffsets146Test extends JodaTestBase { - private final ObjectMapper MAPPER = jodaMapper(); - { - MAPPER.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - MAPPER.enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS); - } - // [datatype-joda#146] - public void testLocalDateSer() throws Exception + public void testLocalDateSerDefault() throws Exception { - final ObjectMapper MAPPER = mapperWithModuleBuilder() + final String inputStr = "2024-12-01T12:00:00+02:00"; + final DateTime inputValue = DateTime.parse(inputStr); + final ObjectMapper mapper = mapperWithModuleBuilder() .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) - .disable(SerializationFeature.WRITE_DATES_WITH_CONTEXT_TIME_ZONE) .build(); - final String inputStr = "2024-12-01T00:00:00+02:00"; - DateTime dateTime = DateTime.parse(inputStr); - assertEquals(q(inputStr), MAPPER.writeValueAsString(dateTime)); + // By default, do adjust timezone to UTC + final String defaultOutput = mapper.writeValueAsString(inputValue); + assertEquals(q("2024-12-01T10:00:00.000Z"), defaultOutput); + + // But if we disable it, no adjustment + final String alternateOutput = mapper.writer() + .without(SerializationFeature.WRITE_DATES_WITH_CONTEXT_TIME_ZONE) + .writeValueAsString(inputValue); + + assertEquals(q(inputStr), alternateOutput); } }