Skip to content

Commit

Permalink
Minor clean up wrt #146 test
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 31, 2024
1 parent a46f82c commit 9788acf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 9788acf

Please sign in to comment.