Clojure JSON: Exception: com.fasterxml.jackson.core.JsonGenerationException: Cannot JSON encode object of class: Clojure JSON: Exception: com.fasterxml.jackson.core.JsonGenerationException: Cannot JSON encode object of class: json json

Clojure JSON: Exception: com.fasterxml.jackson.core.JsonGenerationException: Cannot JSON encode object of class:


Not really enough information. However, this exception is often seen when cheshire does not recognise the data type of something it has been told to encode as json. The error looks like you might be trying to json encode a function rather than output from a function? I would add a println in your endpoint and print out what you believe is being returned. If the output looks like a function object rather than something which json can encode, that is probably the cause.

As to where this is happening, my guess is that your middleware is trying to encode the response body as json.


Yes, its not really enough information. But, according your exception its clear to see that cheshire does not know the type "recursiftion.dao_graph$create_node" that's why its throwing this exception.

The simple solution is parsing it to a known data before sending to Cheshire, for example

(defn my-parser     [data](assoc data :index_with_not_know_type (str (:index_with_not_know_type data))))

Obs: in my case I just cast :index_with_not_know_type value to string

And then, in your case, you can do something like this

(POST "/node/create" request(let [node_object (or (get-in request [:params :data])(get-in request [:body :data])"1ROUTER_ERROR")]{:status 200:headers {"Content-Type" "application/json"}:body (-> (recursiftion.model/createNode node_object)          (my-parser))}))