Skip to content

JsonFormat.Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS not respected when deserialising Instants #272

@pmahony893

Description

@pmahony893

I have a class as follows:

public class InstantWrapper {
    @JsonFormat(without = Feature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
    private Instant myInstant;

    public Instant getMyInstant() { return myInstant; }
    public void setMyInstant(Instant myInstant) { this.myInstant = myInstant; }
}

When serialising, the result uses milliseconds since the epoch; however, when deserialising, it is interpreted as nanoseconds.

I understand that the JavaDoc says "Override for SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS" (saying nothing about DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS), however in my view it's undesirable that a round-trip modifies the data when this option is used.

Is there a way (other than writing my own deserialiser) to override the ObjectMapper's settings so that timestamps are interpreted using milliseconds?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions