|
7 | 7 | [jj.sql.async-boa :as boa] |
8 | 8 | [jj.sql.boa.query.vertx-pg :as vertx-adapter] |
9 | 9 | [jj.tassu :refer [GET POST PUT async-route]] |
10 | | - [jsonista.core :as json] |
| 10 | + [clojure.data.json :as json] |
11 | 11 | [ring-http-exchange.core :as server] |
12 | 12 | [ring-http-exchange.ssl :as ssl]) |
13 | 13 | (:import (io.vertx.core Vertx) |
|
84 | 84 |
|
85 | 85 | (defn- load-json [path] |
86 | 86 | (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))) |
88 | 88 |
|
89 | 89 | (defn- process-item [item ^long m] |
90 | 90 | (assoc item :total (* (:price item) (:quantity item) m))) |
|
124 | 124 | (.toByteArray baos))) |
125 | 125 |
|
126 | 126 | (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)}) |
128 | 128 |
|
129 | 129 | (defn- text-response [s] |
130 | 130 | {:status 200 :headers text-headers :body (str s)}) |
|
148 | 148 | :price (:price row) |
149 | 149 | :quantity (:quantity row) |
150 | 150 | :active (:active row) |
151 | | - :tags (json/read-value (str (:tags row))) |
| 151 | + :tags (:tags row) |
152 | 152 | :rating {:score (:rating_score row) :count (:rating_count row)}}) |
153 | 153 |
|
154 | 154 | (defn- pem->keystore [^String cert-path ^String key-path] |
|
233 | 233 | params (parse-qs (:query-string req)) |
234 | 234 | m (safe-parse-long (get params param-m) 1) |
235 | 235 | 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")] |
238 | 237 | (respond |
239 | 238 | (if (accepts-gzip? (:headers req)) |
240 | 239 | {:status 200 :headers json-gzip-headers :body (gzip-bytes body-bytes)} |
|
261 | 260 | pg-pool |
262 | 261 | (fn [rows] |
263 | 262 | (let [fortunes (sort-by :message (conj rows {:id 0 :message "Additional fortune added at request time."})) |
264 | | - body (fortunes-render {:fortunes fortunes})] |
| 263 | + body ""] |
265 | 264 | (respond {:status 200 :headers html-headers :body body}))) |
266 | 265 | raise)) |
267 | 266 |
|
|
289 | 288 | :price (long (:price row)) |
290 | 289 | :quantity (long (:quantity row)) |
291 | 290 | :active (:active row) |
292 | | - :tags (json/read-value (str (:tags row))) |
| 291 | + :tags (json/read-str (str (:tags row))) |
293 | 292 | :rating {:score (long (:rating_score row)) :count (long (:rating_count row))}}) |
294 | 293 |
|
295 | 294 | (defn- handle-crud-list [pg-pool req respond raise] |
|
316 | 315 | (crud-read-query pg-pool {:id id} |
317 | 316 | (fn [rows] |
318 | 317 | (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))] |
320 | 319 | (crud-cache-set id json-str) |
321 | 320 | (respond {:status 200 :headers crud-miss-headers :body json-str})) |
322 | 321 | (respond {:status 404 :headers json-headers :body not-found-body}))) |
323 | 322 | raise))))) |
324 | 323 |
|
325 | 324 | (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) |
327 | 326 | id (:id body) |
328 | 327 | nm (or (:name body) "New Product") |
329 | 328 | category (or (:category body) "test") |
|
333 | 332 | (fn [rows] |
334 | 333 | (respond {:status 201 |
335 | 334 | :headers json-headers |
336 | | - :body (json/write-value-as-string |
| 335 | + :body (json/write-str |
337 | 336 | {:id (:id (first rows)) |
338 | 337 | :name nm |
339 | 338 | :category category |
|
345 | 344 | (let [id (safe-parse-long (get-in req [:params :id]) nil)] |
346 | 345 | (if (nil? id) |
347 | 346 | (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) |
349 | 348 | nm (or (:name body) "Updated") |
350 | 349 | price (or (:price body) 0) |
351 | 350 | quantity (or (:quantity body) 0)] |
|
356 | 355 | (crud-cache-evict id) |
357 | 356 | (respond {:status 200 |
358 | 357 | :headers json-headers |
359 | | - :body (json/write-value-as-string |
| 358 | + :body (json/write-str |
360 | 359 | {:id id |
361 | 360 | :name nm |
362 | 361 | :price price |
|
0 commit comments