Skip to content

Commit 20baf29

Browse files
committed
Use data.json
1 parent 9686f07 commit 20baf29

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

frameworks/ring-http-exchange/project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[org.clojars.jj/tassu "1.0.4"]
1010
[org.clojars.jj/async-boa-sql "1.0.11"]
1111
[org.clojars.jj/vertx-pg-client-async-boa-adapter "1.0.1"]
12-
[metosin/jsonista "1.0.0"]
12+
[org.clojure/data.json "2.5.2"]
1313
[org.clojars.jj/majavat "2.0.2"]
1414
[io.github.robaho/httpserver "1.0.29"]
1515
[org.clojure/core.cache "1.2.263"]]

frameworks/ring-http-exchange/src/ring/core.clj

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[jj.sql.async-boa :as boa]
88
[jj.sql.boa.query.vertx-pg :as vertx-adapter]
99
[jj.tassu :refer [GET POST PUT async-route]]
10-
[jsonista.core :as json]
10+
[clojure.data.json :as json]
1111
[ring-http-exchange.core :as server]
1212
[ring-http-exchange.ssl :as ssl])
1313
(:import (io.vertx.core Vertx)
@@ -84,7 +84,7 @@
8484

8585
(defn- load-json [path]
8686
(when (.exists (io/file path))
87-
(json/read-value (slurp path) json/keyword-keys-object-mapper)))
87+
(json/read-str (slurp path) :key-fn keyword)))
8888

8989
(defn- process-item [item ^long m]
9090
(assoc item :total (* (:price item) (:quantity item) m)))
@@ -124,7 +124,7 @@
124124
(.toByteArray baos)))
125125

126126
(defn- json-response [data]
127-
{:status 200 :headers json-headers :body (json/write-value-as-string data)})
127+
{:status 200 :headers json-headers :body (json/write-str data)})
128128

129129
(defn- text-response [s]
130130
{:status 200 :headers text-headers :body (str s)})
@@ -148,7 +148,7 @@
148148
:price (:price row)
149149
:quantity (:quantity row)
150150
:active (:active row)
151-
:tags (json/read-value (str (:tags row)))
151+
:tags (:tags row)
152152
:rating {:score (:rating_score row) :count (:rating_count row)}})
153153

154154
(defn- pem->keystore [^String cert-path ^String key-path]
@@ -233,8 +233,7 @@
233233
params (parse-qs (:query-string req))
234234
m (safe-parse-long (get params param-m) 1)
235235
items (map #(process-item % m) (subvec dataset 0 n))
236-
body-bytes (json/write-value-as-bytes
237-
{:items items :count (clojure.core/count items)})]
236+
body-bytes (.getBytes (json/write-str {:items items :count (clojure.core/count items)}) "UTF-8")]
238237
(respond
239238
(if (accepts-gzip? (:headers req))
240239
{:status 200 :headers json-gzip-headers :body (gzip-bytes body-bytes)}
@@ -261,7 +260,7 @@
261260
pg-pool
262261
(fn [rows]
263262
(let [fortunes (sort-by :message (conj rows {:id 0 :message "Additional fortune added at request time."}))
264-
body (fortunes-render {:fortunes fortunes})]
263+
body ""]
265264
(respond {:status 200 :headers html-headers :body body})))
266265
raise))
267266

@@ -289,7 +288,7 @@
289288
:price (long (:price row))
290289
:quantity (long (:quantity row))
291290
:active (:active row)
292-
:tags (json/read-value (str (:tags row)))
291+
:tags (json/read-str (str (:tags row)))
293292
:rating {:score (long (:rating_score row)) :count (long (:rating_count row))}})
294293

295294
(defn- handle-crud-list [pg-pool req respond raise]
@@ -316,14 +315,14 @@
316315
(crud-read-query pg-pool {:id id}
317316
(fn [rows]
318317
(if-let [row (first rows)]
319-
(let [json-str (json/write-value-as-string (transform-crud-row row))]
318+
(let [json-str (json/write-str (transform-crud-row row))]
320319
(crud-cache-set id json-str)
321320
(respond {:status 200 :headers crud-miss-headers :body json-str}))
322321
(respond {:status 404 :headers json-headers :body not-found-body})))
323322
raise)))))
324323

325324
(defn- handle-crud-create [pg-pool req respond raise]
326-
(let [body (json/read-value (:body req) json/keyword-keys-object-mapper)
325+
(let [body (json/read-str (slurp (:body req)) :key-fn keyword)
327326
id (:id body)
328327
nm (or (:name body) "New Product")
329328
category (or (:category body) "test")
@@ -333,7 +332,7 @@
333332
(fn [rows]
334333
(respond {:status 201
335334
:headers json-headers
336-
:body (json/write-value-as-string
335+
:body (json/write-str
337336
{:id (:id (first rows))
338337
:name nm
339338
:category category
@@ -345,7 +344,7 @@
345344
(let [id (safe-parse-long (get-in req [:params :id]) nil)]
346345
(if (nil? id)
347346
(respond {:status 404 :headers json-headers :body not-found-body})
348-
(let [body (json/read-value (:body req) json/keyword-keys-object-mapper)
347+
(let [body (json/read-str (slurp (:body req)) :key-fn keyword)
349348
nm (or (:name body) "Updated")
350349
price (or (:price body) 0)
351350
quantity (or (:quantity body) 0)]
@@ -356,7 +355,7 @@
356355
(crud-cache-evict id)
357356
(respond {:status 200
358357
:headers json-headers
359-
:body (json/write-value-as-string
358+
:body (json/write-str
360359
{:id id
361360
:name nm
362361
:price price

0 commit comments

Comments
 (0)