Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 31, 2024
2 parents e3f9ff9 + 0bb8d01 commit 37cf5b9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tools.jackson.datatype.joda.cfg;

import java.util.Locale;
import java.util.Objects;
import java.util.TimeZone;

import org.joda.time.DateTimeZone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
public class InstantSerializationTest extends JodaTestBase
{
private final ObjectMapper MAPPER = mapperWithModuleBuilder()
.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.build();
.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.enable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.build();

public void testInstantSer() throws Exception {
Instant instant = new Instant(0L);
Expand All @@ -24,7 +24,7 @@ public void testInstantSer() throws Exception {
assertEquals("0", MAPPER.writeValueAsString(instant));

// but if re-configured, as regular ISO-8601 string
assertEquals(quote("1970-01-01T00:00:00.000Z"), MAPPER.writer()
assertEquals(q("1970-01-01T00:00:00.000Z"), MAPPER.writer()
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.writeValueAsString(instant));
}
Expand All @@ -35,7 +35,7 @@ public void testCustomFormatInstantSer() throws Exception
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.without(JsonWriteFeature.ESCAPE_FORWARD_SLASHES)
.writeValueAsString(new FormattedInstant(new Instant(0L)));
assertEquals(aposToQuotes(
assertEquals(a2q(
"{'value':'01/01/1970 00_00_00_000'}"), json);
}

Expand All @@ -50,9 +50,7 @@ public void testInstantConversion() throws Exception

// Create an instant and serialize and additionally serialize the instant as DateTime to demonstrate the difference
org.joda.time.Instant now = new DateTime(1431498572205L).toInstant();

String instantString = mapper.writeValueAsString(now);

assertEquals("\"2015-05-13T06:29:32.205Z\"", instantString);
assertEquals("\"2015-05-13T06:29:32.205Z\"", mapper.writeValueAsString(now));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package tools.jackson.datatype.joda.ser;

import java.io.IOException;

import org.joda.time.DateTimeZone;
import org.joda.time.Interval;

Expand Down Expand Up @@ -38,25 +36,25 @@ static class FormattedInterval

private final ObjectWriter WRITER = MAPPER.writer();

public void testIntervalSerBasic() throws IOException
public void testIntervalSerBasic() throws Exception
{
Interval interval = new Interval(1396439982, 1396440001);
assertEquals(quote("1396439982-1396440001"), MAPPER.writeValueAsString(interval));
assertEquals(q("1396439982-1396440001"), MAPPER.writeValueAsString(interval));

// related to #48
assertEquals(quote("1970-01-17T03:53:59.982Z/1970-01-17T03:54:00.001Z"),
assertEquals(q("1970-01-17T03:53:59.982Z/1970-01-17T03:54:00.001Z"),
WRITER.without(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.writeValueAsString(interval));
}

public void testIntervalSerWithTypeInfo() throws IOException
public void testIntervalSerWithTypeInfo() throws Exception
{
Interval interval = new Interval(1396439982, 1396440001);

ObjectMapper mapper = mapperWithModuleBuilder()
.addMixIn(Interval.class, ObjectConfiguration.class)
.build();
assertEquals("[\"org.joda.time.Interval\"," + quote("1396439982-1396440001") + "]",
.addMixIn(Interval.class, ObjectConfiguration.class)
.build();
assertEquals("[\"org.joda.time.Interval\"," + q("1396439982-1396440001") + "]",
mapper.writeValueAsString(interval));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public T getContents() {
private final ObjectWriter WRITER = MAPPER.writer();

/*
/**********************************************************
/**********************************************************************
/* Tests for LocalDate type
/**********************************************************
/**********************************************************************
*/

public void testLocalDateSer() throws IOException
Expand Down Expand Up @@ -81,15 +81,15 @@ public void testLocalDateSerWithTypeInfo() throws IOException
// dynamically changeable)
ObjectMapper mapper = mapperWithModuleBuilder()
.addMixIn(LocalDate.class, ObjectConfiguration.class)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();
assertEquals("[\"org.joda.time.LocalDate\",\"2001-05-25\"]", mapper.writeValueAsString(date));
}

/*
/**********************************************************
/**********************************************************************
/* Tests for LocalTime type
/**********************************************************
/**********************************************************************
*/

public void testLocalTimeSer() throws IOException
Expand All @@ -101,7 +101,7 @@ public void testLocalTimeSer() throws IOException
// but we can force it to be a String as well (note: here we assume this is
// dynamically changeable)
ObjectMapper mapper = mapperWithModuleBuilder()
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();
assertEquals(q("13:20:54.000"), mapper.writeValueAsString(date));
}
Expand Down Expand Up @@ -135,16 +135,16 @@ public void testLocalTimeSerWithTypeInfo() throws IOException
// dynamically changeable)
ObjectMapper mapper = mapperWithModuleBuilder()
.addMixIn(LocalTime.class, ObjectConfiguration.class)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();
assertEquals("[\"org.joda.time.LocalTime\",\"13:20:54.000\"]",
mapper.writeValueAsString(date));
}

/*
/**********************************************************
/**********************************************************************
/* Tests for LocalDateTime type
/**********************************************************
/**********************************************************************
*/

public void testLocalDateTimeSer() throws IOException
Expand All @@ -156,7 +156,7 @@ public void testLocalDateTimeSer() throws IOException
// but we can force it to be a String as well (note: here we assume this is
// dynamically changeable)
ObjectMapper mapper = mapperWithModuleBuilder()
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();
assertEquals(q("2001-05-25T10:15:30.037"), mapper.writeValueAsString(date));
}
Expand All @@ -171,15 +171,16 @@ public void testLocalDateTimeSerWithTypeInfo() throws IOException
// dynamically changeable)
ObjectMapper mapper = mapperWithModuleBuilder()
.addMixIn(LocalDateTime.class, ObjectConfiguration.class)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();
assertEquals("[\"org.joda.time.LocalDateTime\",\"2001-05-25T10:15:30.037\"]", mapper.writeValueAsString(date));
assertEquals("[\"org.joda.time.LocalDateTime\",\"2001-05-25T10:15:30.037\"]",
mapper.writeValueAsString(date));
}

/*
/**********************************************************
/**********************************************************************
/* Tests for Period type
/**********************************************************
/**********************************************************************
*/

public void testPeriodSer() throws IOException
Expand All @@ -198,9 +199,9 @@ public void testPeriodSerWithTypeInfo() throws IOException
}

/*
/**********************************************************
/**********************************************************************
/* Tests for Duration type
/**********************************************************
/**********************************************************************
*/

public void testDurationSer() throws IOException
Expand Down

0 comments on commit 37cf5b9

Please sign in to comment.