Skip to content

Commit

Permalink
Fix cson serialization for fully qualified tagged literals
Browse files Browse the repository at this point in the history
  • Loading branch information
djblue committed Jan 11, 2025
1 parent a42b2c7 commit 5a1761b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/portal/runtime/cson.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -754,11 +754,14 @@
:cljr clojure.lang.TaggedLiteral
:cljs TaggedLiteral)
ToJson
(-to-json [value buffer]
(-to-json [{:keys [tag form]} buffer]
(-> buffer
(json/push-string "tag")
(json/push-string (name (:tag value)))
(to-json (:form value)))))
(json/push-string
(if-let [ns (namespace tag)]
(str ns "/" (name tag))
(name tag)))
(to-json form))))

(defn- ->tagged-literal [buffer]
(tagged-literal (symbol (json/next-string buffer)) (->value buffer)))
Expand Down
5 changes: 3 additions & 2 deletions test/portal/runtime/cson_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@
#?(:clj (UUID/randomUUID)
:cljr (Guid/NewGuid)
:cljs (random-uuid))
(tagged-literal 'tag :value)])
(tagged-literal 'tag :value)
(tagged-literal 'ns/tag :value)])

(deftest tagged-objects
(doseq [value tagged]
(is (= (pass value) (pass value)))))
(is (= (pass value) value))))

(defn meta* [v]
#?(:bb (dissoc (meta v) :type) :cljr (meta v) :clj (meta v) :cljs (meta v)))
Expand Down

0 comments on commit 5a1761b

Please sign in to comment.