Skip to content

Commit

Permalink
Fix all but last 2 unit test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 5, 2025
1 parent c380926 commit d3d2571
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ static class LDTWrapper {
public LDTWrapper(LocalDateTime v) { value = v; }
}

private final static ObjectMapper MAPPER = newMapper();
// 05-Feb-2025, tatu: Use Jackson 2.x defaults wrt as-timestamps
// serialization
private final static ObjectMapper MAPPER = mapperBuilder()
.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();

@Test
public void testSerializationAsTimestamp01() throws Exception
Expand Down Expand Up @@ -76,10 +80,9 @@ public void testSerializationAsTimestamp03Nanosecond() throws Exception
public void testSerializationAsTimestamp03Millisecond() throws Exception
{
LocalDateTime time = LocalDateTime.of(2013, Month.AUGUST, 21, 9, 22, 0, 57);
ObjectMapper m = newMapperBuilder()
.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
.build();
String value = m.writeValueAsString(time);
String value = MAPPER.writer()
.without(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
.writeValueAsString(time);
assertEquals("[2013,8,21,9,22,0,0]", value);
}

Expand All @@ -88,22 +91,19 @@ public void testSerializationAsTimestamp04Nanosecond() throws Exception
{
LocalDateTime time = LocalDateTime.of(2005, Month.NOVEMBER, 5, 22, 31, 5, 829837);

final ObjectMapper m = newMapperBuilder()
.enable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
.build();
String value = m.writeValueAsString(time);
String value = MAPPER.writer()
.with(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
.writeValueAsString(time);
assertEquals("[2005,11,5,22,31,5,829837]", value);
}

@Test
public void testSerializationAsTimestamp04Millisecond() throws Exception
{
LocalDateTime time = LocalDateTime.of(2005, Month.NOVEMBER, 5, 22, 31, 5, 422829837);

final ObjectMapper m = newMapperBuilder()
.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
.build();
String value = m.writeValueAsString(time);
String value = MAPPER.writer()
.without(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
.writeValueAsString(time);
assertEquals("[2005,11,5,22,31,5,422]", value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
public class WriteNanosecondsTest extends ModuleTestBase
{
public static final ZoneId UTC = ZoneId.of("UTC");
private static ObjectMapper MAPPER = newMapper();

static class DummyClass<T> {
// 05-Feb-2025, tatu: Use Jackson 2.x defaults wrt as-timestamps
// serialization
private final static ObjectMapper MAPPER = mapperBuilder()
.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();

public static class DummyClass<T> {
@JsonFormat(with = JsonFormat.Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
private final T nanoseconds;

Expand Down

0 comments on commit d3d2571

Please sign in to comment.