is it possible to use Jackson with nanoseconds value is it possible to use Jackson with nanoseconds value json json

is it possible to use Jackson with nanoseconds value


Yes, it is possible to use Jackson with nanoseconds value; to preserve nanoseconds in Java 8 you can use java.util.Date or java.sql.Timestamp (assuming you haven't disabled Jackson configuration DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS and SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, which are enabled by default).

Before Java 8 you can use a java.math.BigDecimal to store the number of days since epoch plus fractional time of day. Or just keep the value in its String representation. Java 7 and prior versions don't keep nanoseconds in dates, only milliseconds. So if you convert the value to a java.util.Date or one of its subclasses like java.sql.Timestamp, you will have precision only to milliseconds. Therefore java.text.DateFormat is not useful here if you are using it to convert to any kind of java Date in a pre-Java 8 environment.

Here is a further discussion of nanoseconds in java Timestamps: java.sql.Timestamp way of storing NanoSeconds