Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns freeze.core)
- (def b64e (java.util.Base64/getEncoder))
- (def b64d (java.util.Base64/getDecoder))
- (defn deserialize [s]
- "Deserialize string into its Java object."
- (with-open [bstream (java.io.ByteArrayInputStream. (.decode b64d s))
- objstream (java.io.ObjectInputStream. bstream)]
- (.readObject objstream)))
- (defmethod clojure.core/print-dup java.io.Serializable [o w]
- (let [ba (with-open [bytestream (java.io.ByteArrayOutputStream.)
- objstream (java.io.ObjectOutputStream. bytestream)]
- (.writeObject objstream o)
- (.toByteArray bytestream))
- string (.encodeToString b64e ba)]
- (.write w (str "=(freeze.core/deserialize \"" string "\")"))))
- ;; Now for the test that fails.
- (def t (java.time.LocalDateTime/now)) ;; => _
- (def s (binding [*print-dup* true] (pr-str x)))
- (read-string "#=(+ 1 2)") ;; => 3
- (read-string s) ;; => =
- (freeze.core/deserialize "rO0ABXNyAA1qYXZhLnRpbWUuU2VylV2EuhsiSLIMAAB4cHcOBQAAB98GDxAGEA1Z+AB4") ;; => #<LocalDateTime blah>
Advertisement
Add Comment
Please, Sign In to add comment