add functional-property

main
Michael Jerger 10 months ago
parent 3eff9a628e
commit a612f070db

@ -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")))
(map
serialize-element
(merge
{(keyword "@context") "https://www.w3.org/ns/activitystreams"}
as-map))
:escape-slash false))

@ -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"}))))
{::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"}))))
Loading…
Cancel
Save