Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonIntegerFormatVisitor;
Expand Down Expand Up @@ -63,7 +64,12 @@ protected DurationSerializer withFormat(DateTimeFormatter dtf,
Boolean useTimestamp, JsonFormat.Shape shape) {
return new DurationSerializer(this, dtf, useTimestamp);
}


@Override
protected SerializationFeature getTimestampsFeature() {
return SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS;
}

@Override
public void serialize(Duration duration, JsonGenerator generator,
SerializerProvider provider) throws IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ protected void _acceptTimestampVisitor(JsonFormatVisitorWrapper visitor, JavaTyp
}
}

protected SerializationFeature getTimestampsFeature() {
return SerializationFeature.WRITE_DATES_AS_TIMESTAMPS;
}

protected boolean useTimestamp(SerializerProvider provider) {
if (_useTimestamp != null) {
return _useTimestamp.booleanValue();
Expand All @@ -184,7 +188,7 @@ protected boolean useTimestamp(SerializerProvider provider) {
}
}
// assume that explicit formatter definition implies use of textual format
return _formatter == null && provider.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
return _formatter == null && provider.isEnabled(getTimestampsFeature());
}

protected boolean _useTimestampExplicitOnly(SerializerProvider provider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void testSerializationAsString01() throws Exception
{
Duration duration = Duration.ofSeconds(60L, 0);
String value = WRITER
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.without(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.writeValueAsString(duration);

assertNotNull("The value should not be null.", value);
Expand All @@ -104,7 +104,7 @@ public void testSerializationAsString02() throws Exception
{
Duration duration = Duration.ofSeconds(13498L, 8374);
String value = WRITER
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.without(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.writeValueAsString(duration);

assertNotNull("The value should not be null.", value);
Expand Down Expand Up @@ -147,7 +147,7 @@ public void testSerializationWithTypeInfo02() throws Exception
public void testSerializationWithTypeInfo03() throws Exception
{
ObjectMapper mapper = newMapperBuilder()
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.addMixIn(TemporalAmount.class, MockObjectConfiguration.class)
.build();
Duration duration = Duration.ofSeconds(13498L, 8374);
Expand Down