clojure neocons を使用して Neo4j データストアにノードを作成しようとしていますが、json のフォーマットに関連していると思われるエラーが発生しています。
Exception: com.fasterxml.jackson.core.JsonGenerationException: Cannot JSON encode object of class: class recursiftion.dao_graph$create_node: recursiftion.dao_graph$create_node@32693b5
generate.clj:148 cheshire.generate/generate
generate.clj:119 cheshire.generate/generate
core.clj:31 cheshire.core/generate-string
core.clj:21 cheshire.core/generate-string
cypher.clj:51 clojurewerkz.neocons.rest.cypher/query
core.clj:2440 clojure.core/comp[fn]
dao_graph.clj:428 recursiftion.dao-graph/create-node
model.clj:131 recursiftion.model/createNode
controller.clj:206 recursiftion.controller/fn
core.clj:99 compojure.core/make-route[fn]
core.clj:45 compojure.core/if-route[fn]
core.clj:30 compojure.core/if-method[fn]
core.clj:112 compojure.core/routing[fn]
core.clj:2570 clojure.core/some
core.clj:112 compojure.core/routing
RestFn.java:139 clojure.lang.RestFn.applyTo
core.clj:632 clojure.core/apply
core.clj:117 compojure.core/routes[fn]
keyword_params.clj:32 ring.middleware.keyword-params/wrap-keyword-params[fn]
...
エラー レポートに基づいて、これは Cheshire に関連している可能性があると思われます。しかし、エラーが発生したファイルに Cheshire ライブラリが含まれていないため、混乱しています。
cors POST & GET リクエストを作成しており、controller.clj から JSON を返す必要があるため、これをラッパーとして使用しています。
(def app
(-> (handler/api app-routes)
(middleware/wrap-json-body {:keywords? true})
(middleware/wrap-json-response)
(wrap-cors routes #"^http://localhost:9000$")))
以下は、私のcontroller.cljで参照されているライブラリです
(ns recursiftion.controller
(:use [ring.adapter.jetty :only [run-jetty]]
[recursiftion.websocket :only [wamp-handler]]
[recursiftion.config :only [conf]]
)
(:require [compojure.core :refer :all]
[compojure.handler :as handler]
[compojure.route :as route]
[clojure.java.io :as io]
[ring.util.io :refer [string-input-stream]]
[ring.util.response :as resp]
[ring.util.response :refer [response]]
[ring.middleware.json :as middleware]
[ring.middleware.cors :refer [wrap-cors]]
[environ.core :refer [env]]
[cheshire.core :refer :all]
[recursiftion.model :as model]
[monger.json]
[clojure.pprint :refer [pprint]]))
controller.clj の POST エンドポイント コードは次のとおりです。
(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)
}
))
私のモデルを通過し、dao_graph.clj にある参照ライブラリは次のとおりです。
(ns recursiftion.dao_graph
(:require [clojure.string]
[clojurewerkz.neocons.rest :as nr]
[clojurewerkz.neocons.rest.cypher :as cy]
[clojure.pprint :refer [pprint]])
(:import [org.bson.types.ObjectId])
)
以下は、dao_graph.clj 内で呼び出される関数の定義です。
(defn create-node [ nodeobj ]
(let [ _nodeobj nodeobj ]
(cy/tquery conn create-node { :_nodetype (get-in _nodeobj [:type]) })))
そして、「...」をキーとしてマップを返す暗号クエリを次に示します。
(def create-node "CREATE (m:{_nodetype})
RETURN M;")
この問題の解決にご協力いただき、誠にありがとうございます。