$ clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.520"} com.cognitect/transit-cljs {:mvn/version "0.8.256"} com.cognitect/transit-js {:mvn/version "0.8.861"} cljs-bean {:mvn/version "1.4.0"}}}' -m cljs.main -re node -r
ClojureScript 1.10.520
(require '[cognitect.transit :as t]
'[cljs-bean.core :refer [->clj]]
'[cljs-bean.transit])
nil
cljs.user=> (defn roundtrip [x]
(let [w (t/writer :json
{:handlers (cljs-bean.transit/writer-handlers)
:transform t/write-meta})
r (t/reader :json)]
(t/read r (t/write w x))))
#'cljs.user/roundtrip
cljs.user=> (def x (with-meta (->clj #js {:a 1}) {:id "some-ref" :ref "/some/path"}))
#'cljs.user/x
cljs.user=> (type x)
cljs-bean.core/Bean
cljs.user=> (meta x)
{:id "some-ref", :ref "/some/path"}
cljs.user=> (def y (roundtrip x))
#'cljs.user/y
cljs.user=> y
{:a 1}
cljs.user=> (type y)
cljs.core/PersistentArrayMap
cljs.user=> (meta y)
{:id "some-ref", :ref "/some/path"}
Last active
September 8, 2019 21:33
-
-
Save mfikes/3a160a1504debd31e5771736256ca022 to your computer and use it in GitHub Desktop.
Serializing CLJS Bean instances via transit preserving meta
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Commits in
transit-clj
cognitect/transit-clj@a823f3btransit-cljs
cognitect/transit-cljs@35663b3