This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-11
Channels
- # bangalore-clj (1)
- # beginners (24)
- # boot (134)
- # boulder-clojurians (2)
- # cider (3)
- # cljs-dev (2)
- # cljsjs (44)
- # clojars (9)
- # clojure (60)
- # clojure-greece (2)
- # clojure-quebec (1)
- # clojure-russia (44)
- # clojure-spec (15)
- # clojure-uk (1)
- # clojurescript (37)
- # core-matrix (1)
- # datomic (7)
- # emacs (1)
- # hoplon (154)
- # liberator (3)
- # mount (2)
- # om (20)
- # onyx (2)
- # pedestal (3)
- # planck (12)
- # re-frame (26)
- # reagent (32)
- # uncomplicate (4)
I'm trying to get Liberator to send UUIDs as strings when JSON is the content type. right now I'm getting this error:
Don't know how to write JSON of class java.util.UUID
I tried to solve the problem with this code, but it doesn't seem to have any effect. am I missing something here?
(ns server
(:require [liberator.representation :as lib-rep]
[clojure.data.json :as json]))
(defn uuid->str [key value]
(if (instance? java.util.UUID value)
(str value)
value))
(remove-method lib-rep/render-map-generic "application/json")
(defmethod lib-rep/render-map-generic "application/json" [data context]
(json/write-str data {:value-fn uuid->str}))
I would use a custom function for :as-response
that delegates to the default as-response for non-JSON types.