serialization - Deserialize millisecond timestamp to java.time.Instant -


i'm attempting read json file using jackson , store 1 of fields stored epoch milliseconds java instant, deserialization not behaving expected.

here seeing when trying read timestamp:

1503115200000

jackson setting instant field +49601-10-28t16:00:00z.

this appears occurring because jackson's default read timestamp instant.ofepochsecond(long l) instead of instant.ofepochmilli(long l).

is there way set jackson objectmapper use ofepochmilli method instead? have objectmapper:

objectmapper om = new objectmapper()             .registermodule(new javatimemodule())             .configure(serializationfeature.write_date_timestamps_as_nanoseconds, false)             .configure(serializationfeature.fail_on_empty_beans, false)             .configure(deserializationfeature.fail_on_unknown_properties, false)             .setserializationinclusion(include.non_null); 

note

if change input json iso date such 2017-08-19t04:00:00z or epoch seconds such 1503115200 instant field able set properly.

unfortunately json input must epoch milliseconds e.g. 1503115200000.

from https://github.com/fasterxml/jackson-modules-java8/blob/master/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/javatimemodule.java:

the more ambiguous integer types read fractional seconds without decimal point if {@code read_date_timestamps_as_nanoseconds} enabled (it default), , otherwise read milliseconds.

so need disable read_date_timestamps_as_nanoseconds.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -