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.