diff --git a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/core.cljc b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/core.cljc index 5485fbc..168f567 100644 --- a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/core.cljc +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/core.cljc @@ -5,10 +5,18 @@ [org.domaindrivenarchitecture.activity-pub-poc.activitystreams2 :as as] [clojure.data.json :as json])) +( defn serialize-element [elem] + (if (and (sh/is-functional-property? (key elem)) + (sequential? (val elem))) + {(key elem) (first (val elem))} + {(key elem) (val elem)})) + (defn serialize [as-map] (json/write-str - (assoc - as-map - (keyword "@context") - "https://www.w3.org/ns/activitystreams"))) \ No newline at end of file + (map + serialize-element + (merge + {(keyword "@context") "https://www.w3.org/ns/activitystreams"} + as-map)) + :escape-slash false)) \ No newline at end of file diff --git a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/core_test.cljc b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/core_test.cljc index 69275b2..2bbc8b6 100644 --- a/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/core_test.cljc +++ b/src/test/cljc/org/domaindrivenarchitecture/activity_pub_poc/core_test.cljc @@ -6,16 +6,18 @@ [org.domaindrivenarchitecture.activity-pub-poc.core :as sut])) (deftest should-serailize - (is (= (str "{\"@context\": \"https://www.w3.org/ns/activitystreams\", " - "\"summary\": \"Sally liked a note\", " - "\"type\": \"Like\", " - "\"actor\": {" - "\"type\": \"Person\", " - "\"name\": \"Sally\"}, " - "\"object\": \"http://example.org/notes/1\"}") + (is (= (str "{\"@context\":\"https://www.w3.org/ns/activitystreams\"," + "\"id\":\"http://example.org/likes/1\"," + "\"summary\":\"Sally liked a note\"," + "\"type\":\"Like\"," + "\"actor\":{" + "\"type\":\"Person\"," + "\"name\":\"Sally\"}," + "\"object\":\"http://example.org/notes/1\"}") (sut/serialize - {:summary "Sally liked a note", - :type "Like", - :actor {:type "Person", - :name "Sally"}, - :object "http://example.org/notes/1"})))) \ No newline at end of file + {::as/id ["http://example.org/likes/1"] + ::as/summary "Sally liked a note", + ::as/type "Like", + ::as/actor {::as/type "Person", + ::as/name "Sally"}, + ::as/object "http://example.org/notes/1"})))) \ No newline at end of file