add functional-property
This commit is contained in:
parent
3eff9a628e
commit
a612f070db
2 changed files with 26 additions and 16 deletions
|
@ -5,10 +5,18 @@
|
||||||
[org.domaindrivenarchitecture.activity-pub-poc.activitystreams2 :as as]
|
[org.domaindrivenarchitecture.activity-pub-poc.activitystreams2 :as as]
|
||||||
[clojure.data.json :as json]))
|
[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
|
(defn serialize
|
||||||
[as-map]
|
[as-map]
|
||||||
(json/write-str
|
(json/write-str
|
||||||
(assoc
|
(map
|
||||||
as-map
|
serialize-element
|
||||||
(keyword "@context")
|
(merge
|
||||||
"https://www.w3.org/ns/activitystreams")))
|
{(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]))
|
[org.domaindrivenarchitecture.activity-pub-poc.core :as sut]))
|
||||||
|
|
||||||
(deftest should-serailize
|
(deftest should-serailize
|
||||||
(is (= (str "{\"@context\": \"https://www.w3.org/ns/activitystreams\", "
|
(is (= (str "{\"@context\":\"https://www.w3.org/ns/activitystreams\","
|
||||||
"\"summary\": \"Sally liked a note\", "
|
"\"id\":\"http://example.org/likes/1\","
|
||||||
"\"type\": \"Like\", "
|
"\"summary\":\"Sally liked a note\","
|
||||||
"\"actor\": {"
|
"\"type\":\"Like\","
|
||||||
"\"type\": \"Person\", "
|
"\"actor\":{"
|
||||||
"\"name\": \"Sally\"}, "
|
"\"type\":\"Person\","
|
||||||
"\"object\": \"http://example.org/notes/1\"}")
|
"\"name\":\"Sally\"},"
|
||||||
|
"\"object\":\"http://example.org/notes/1\"}")
|
||||||
(sut/serialize
|
(sut/serialize
|
||||||
{:summary "Sally liked a note",
|
{::as/id ["http://example.org/likes/1"]
|
||||||
:type "Like",
|
::as/summary "Sally liked a note",
|
||||||
:actor {:type "Person",
|
::as/type "Like",
|
||||||
:name "Sally"},
|
::as/actor {::as/type "Person",
|
||||||
:object "http://example.org/notes/1"}))))
|
::as/name "Sally"},
|
||||||
|
::as/object "http://example.org/notes/1"}))))
|
Loading…
Reference in a new issue