diff --git a/pom.xml b/pom.xml index 8468125..08e0bb2 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,15 @@ Joda (https://www.joda.org/joda-time/) data types. + + org.apache.maven.plugins + maven-surefire-plugin + + + tools/jackson/**/failing/*.java + + + diff --git a/src/test/java/tools/jackson/datatype/joda/JodaTestBase.java b/src/test/java/tools/jackson/datatype/joda/JodaTestBase.java index 11caa0c..58acbbf 100644 --- a/src/test/java/tools/jackson/datatype/joda/JodaTestBase.java +++ b/src/test/java/tools/jackson/datatype/joda/JodaTestBase.java @@ -1,20 +1,18 @@ package tools.jackson.datatype.joda; -import java.io.IOException; import java.text.DateFormat; import java.util.Arrays; import java.util.TimeZone; +import junit.framework.TestCase; + import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import tools.jackson.databind.ObjectMapper; import tools.jackson.databind.cfg.CoercionAction; import tools.jackson.databind.cfg.CoercionInputShape; import tools.jackson.databind.json.JsonMapper; -import junit.framework.TestCase; - import org.joda.time.Instant; import org.joda.time.YearMonth; import org.joda.time.MonthDay; @@ -123,17 +121,21 @@ protected void verifyException(Throwable e, String... matches) fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\""); } - public String quote(String str) { + public String q(String str) { return '"'+str+'"'; } - protected String aposToQuotes(String json) { + // @Deprecated + public String quote(String str) { + return q(str); + } + + protected String a2q(String json) { return json.replace("'", "\""); } - protected T readAndMapFromString(ObjectMapper m, String input, Class cls) - throws IOException - { - return (T) m.readValue("\""+input+"\"", cls); + // @Deprecated + protected String aposToQuotes(String json) { + return a2q(json); } } diff --git a/src/test/java/tools/jackson/datatype/joda/failing/DateTimeSerializationWithOffsets146Test.java b/src/test/java/tools/jackson/datatype/joda/failing/DateTimeSerializationWithOffsets146Test.java new file mode 100644 index 0000000..12abf39 --- /dev/null +++ b/src/test/java/tools/jackson/datatype/joda/failing/DateTimeSerializationWithOffsets146Test.java @@ -0,0 +1,25 @@ +package tools.jackson.datatype.joda.failing; + +import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.SerializationFeature; + +import tools.jackson.datatype.joda.JodaTestBase; + +import org.joda.time.*; + +// [datatype-joda#146]: disable overwriting of timezone +public class DateTimeSerializationWithOffsets146Test extends JodaTestBase +{ + // [datatype-joda#146] + public void testDateTimeSerializationWithOffsets146() throws Exception + { + 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)); + } +} diff --git a/src/test/java/tools/jackson/datatype/joda/ser/JodaSerializationTest.java b/src/test/java/tools/jackson/datatype/joda/ser/JodaSerializationTest.java index e85a8d6..9aff659 100644 --- a/src/test/java/tools/jackson/datatype/joda/ser/JodaSerializationTest.java +++ b/src/test/java/tools/jackson/datatype/joda/ser/JodaSerializationTest.java @@ -57,7 +57,7 @@ public void testLocalDateSer() throws IOException // but we can force it to be a String as well (note: here we assume this is // dynamically changeable) - assertEquals(quote("2001-05-25"), + assertEquals(q("2001-05-25"), WRITER.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).writeValueAsString(date)); // We can also configure beans to not include empty values. In this case, @@ -103,8 +103,7 @@ public void testLocalTimeSer() throws IOException ObjectMapper mapper = mapperWithModuleBuilder() .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) .build(); - assertEquals(quote("13:20:54.000"), mapper.writeValueAsString(date)); - + assertEquals(q("13:20:54.000"), mapper.writeValueAsString(date)); } public void testLocalTimeSerWithFormatOverride() throws IOException @@ -120,9 +119,9 @@ public void testLocalTimeSerWithFormatOverride() throws IOException .addModule(testModule) .build(); - assertEquals(quote("13:20"), mapper.writeValueAsString(date)); + assertEquals(q("13:20"), mapper.writeValueAsString(date)); - assertEquals(aposToQuotes("{'contents':'13:20'}"), mapper.writeValueAsString(new Container<>(date))); + assertEquals(a2q("{'contents':'13:20'}"), mapper.writeValueAsString(new Container<>(date))); } @@ -140,7 +139,6 @@ public void testLocalTimeSerWithTypeInfo() throws IOException .build(); assertEquals("[\"org.joda.time.LocalTime\",\"13:20:54.000\"]", mapper.writeValueAsString(date)); - } /* @@ -160,7 +158,7 @@ public void testLocalDateTimeSer() throws IOException ObjectMapper mapper = mapperWithModuleBuilder() .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) .build(); - assertEquals(quote("2001-05-25T10:15:30.037"), mapper.writeValueAsString(date)); + assertEquals(q("2001-05-25T10:15:30.037"), mapper.writeValueAsString(date)); } public void testLocalDateTimeSerWithTypeInfo() throws IOException @@ -187,7 +185,7 @@ public void testLocalDateTimeSerWithTypeInfo() throws IOException public void testPeriodSer() throws IOException { Period in = new Period(1, 2, 3, 4); - assertEquals(quote("PT1H2M3.004S"), MAPPER.writeValueAsString(in)); + assertEquals(q("PT1H2M3.004S"), MAPPER.writeValueAsString(in)); } public void testPeriodSerWithTypeInfo() throws IOException @@ -211,7 +209,7 @@ public void testDurationSer() throws IOException String json = MAPPER.writeValueAsString(d); assertEquals("3123422", json); - assertEquals(quote("PT3123.422S"), MAPPER.writer() + assertEquals(q("PT3123.422S"), MAPPER.writer() .without(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) .writeValueAsString(d)); } @@ -231,24 +229,24 @@ public void testMonthDaySer() throws Exception { MonthDay monthDay = new MonthDay(7, 23); String json = MAPPER.writeValueAsString(monthDay); - assertEquals(quote("--07-23"), json); + assertEquals(q("--07-23"), json); } public void testCustomMonthDaySer() throws Exception { String json = MAPPER.writeValueAsString(new FormattedMonthDay(new MonthDay(7, 23))); - assertEquals(aposToQuotes("{'value':'07:23'}"), json); + assertEquals(a2q("{'value':'07:23'}"), json); } public void testYearMonthSer() throws Exception { String json = MAPPER.writeValueAsString(new YearMonth(2013, 8)); - assertEquals(quote("2013-08"), json); + assertEquals(q("2013-08"), json); } public void testCustomYearMonthSer() throws Exception { String json = MAPPER.writeValueAsString(new FormattedYearMonth(new YearMonth(2013, 8))); - assertEquals(aposToQuotes("{'value':'2013/08'}"), json); + assertEquals(a2q("{'value':'2013/08'}"), json); } }