jvm

RAJKUMAR 2023-07-15T06:15:35.501489Z

Hi

RAJKUMAR 2023-07-15T06:15:50.202449Z

I'm having issue with java version and jackson

RAJKUMAR 2023-07-15T06:16:06.832709Z

I'm having behavior of metosin/jsonista 0.3.7 work differently on java 1.8 and java 11

2023-07-15T07:00:22.418849Z

Almost certainly time/instant is not returning a joda time object, but a java Instant, so the first thing to do would be to use the Jackson module for the new java date time stuff

RAJKUMAR 2023-07-15T07:26:12.228369Z

okay I updated the code inline above

RAJKUMAR 2023-07-15T07:26:19.085729Z

to print (println (type instant))

RAJKUMAR 2023-07-15T07:26:49.626919Z

in both cases (i.e., java 8 and 11) it is printing java.time.Instant

RAJKUMAR 2023-07-15T06:16:20.617519Z

below is the java code

RAJKUMAR 2023-07-15T06:16:27.554179Z

(ns com.example.jsonista-issue
  (:refer-clojure :exclude [read])
  (:require
   [jsonista.core :as json]
   [java-time.api :as time])
  (:import
   (com.fasterxml.jackson.databind ObjectMapper)
   (com.fasterxml.jackson.datatype.joda JodaModule)))

(def ^ObjectMapper base-object-mapper
  (json/object-mapper {:decode-key-fn true
                       :modules       [(JodaModule.)]
                       :date-format   "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"}))

(defn generate-string [obj]
  (json/write-value-as-string obj base-object-mapper))

(defn -main [& args]
  (let [instant (time/instant)].   (println (type instant))
    (println (System/getProperty "java.version"))
    (println (System/getProperty "java.vendor"))
    (println (generate-string instant))))

RAJKUMAR 2023-07-15T06:16:48.675049Z

in 1.8 it gives below output

RAJKUMAR 2023-07-15T06:16:50.444249Z

1.8.0_352
Azul Systems, Inc.
"2023-07-15T06:06:22.595Z"

RAJKUMAR 2023-07-15T06:16:59.554159Z

and java 11 it gives below output

RAJKUMAR 2023-07-15T06:17:34.489659Z

11.0.17
Azul Systems, Inc.
"2023-07-15T06:08:48.553587Z"

RAJKUMAR 2023-07-15T06:17:46.056179Z

if you see in java 11 the precision is higher

RAJKUMAR 2023-07-15T06:19:01.575419Z

Any idea how to fix this?