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 168f567..e537fd4 100644 --- a/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/core.cljc +++ b/src/main/cljc/org/domaindrivenarchitecture/activity_pub_poc/core.cljc @@ -1,22 +1,30 @@ (ns org.domaindrivenarchitecture.activity-pub-poc.core (:require [clojure.spec.alpha :as s] + [clojure.walk :as walk] [orchestra.core :refer [defn-spec]] [org.domaindrivenarchitecture.activity-pub-poc.spec-helper :as sh] - [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 normalize-value [v] + (cond (map? v) + (walk/walk normalize-functional-property identity v) + (sequential? v) + (map normalize-value v) + :else v)) + +(defn normalize-functional-property [elem] + (let [k (first elem) + v (second elem)] + (cond (and + (sequential? v) + (sh/is-functional-property? k)) + {k (first (normalize-value v))} + :else {k (normalize-value v)}))) (defn serialize [as-map] (json/write-str - (map - serialize-element - (merge - {(keyword "@context") "https://www.w3.org/ns/activitystreams"} - as-map)) + (merge + {(keyword "@context") "https://www.w3.org/ns/activitystreams"} + (walk/walk normalize-functional-property identity as-map)) :escape-slash false)) \ No newline at end of file