Skip to content

DurationSerializer ignores format pattern if nano-second serialization enabled #224

@Sam-Kruglov

Description

@Sam-Kruglov

@Override
protected DurationSerializer withFormat(DateTimeFormatter dtf,
Boolean useTimestamp, JsonFormat.Shape shape) {
return new DurationSerializer(this, dtf, useTimestamp);
}

If I do this, I expect an integer number in JSON representing the number minutes:

@JsonFormat(pattern = "MINUTES")
@JsonProperty("durationInMins")
Duration duration;

But it serializes it as nanoseconds. After some debugging, I decided to add , shape = NUMBER_INT in order to force com.fasterxml.jackson.datatype.jsr310.ser.JSR310FormattedSerializerBase#useNanoseconds respond false, but it has no effect because shape is not used in the factory method I linked above.

Found a workaround: adding , without = JsonFormat.Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS to @JsonFormat. However, it only works if I add it to each property, adding it on class level has no effect.

Metadata

Metadata

Assignees

Labels

json-formatMissing handling of `@JsonFormat` property annotation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions