Просмотр исходного кода

Use cheshire for JSON de/encoding.

It looks to be a little less flexible, but it supports encoding dates
(but not decoding them, for some reason?).
Lucas Stadler лет назад: 13
Родитель
Сommit
17af9c99d4
2 измененных файлов с 4 добавлено и 4 удалено
  1. 1 1
      clj/project.clj
  2. 3 3
      clj/shame.clj

+ 1 - 1
clj/project.clj

1
(defproject lp-clj "0.0"
1
(defproject lp-clj "0.0"
2
  :description "Playing around with Clojure"
2
  :description "Playing around with Clojure"
3
  :dependencies [[org.clojure/clojure "1.4.0"]
3
  :dependencies [[org.clojure/clojure "1.4.0"]
4
                 [org.clojure/data.json "0.2.1"]
5
                 [compojure "1.1.5"]
4
                 [compojure "1.1.5"]
6
                 [ring-middleware-format "0.2.4"]
5
                 [ring-middleware-format "0.2.4"]
6
                 [cheshire "5.0.1"]
7
                 [hiccup "1.0.2"]]
7
                 [hiccup "1.0.2"]]
8
  :plugins [[lein-ring "0.8.2"]]
8
  :plugins [[lein-ring "0.8.2"]]
9
  :ring {:handler shame/serve}
9
  :ring {:handler shame/serve}

+ 3 - 3
clj/shame.clj

1
(ns shame
1
(ns shame
2
  (:use [clojure.data.json :as json :only []])
3
  (:use compojure.core)
2
  (:use compojure.core)
4
  (:require [compojure.handler :as handler]
3
  (:require [compojure.handler :as handler]
5
            [compojure.route :as route])
4
            [compojure.route :as route])
8
  (:use ring.middleware.stacktrace)
7
  (:use ring.middleware.stacktrace)
9
  (:use [ring.middleware.format-response :only [wrap-restful-response]])
8
  (:use [ring.middleware.format-response :only [wrap-restful-response]])
10
  (:use [ring.middleware.format-params :only [wrap-restful-params]])
9
  (:use [ring.middleware.format-params :only [wrap-restful-params]])
10
  (:require [cheshire.core :as json])
11
  (:use hiccup.core))
11
  (:use hiccup.core))
12
12
13
13
70
;; "backend"
70
;; "backend"
71
71
72
(defn read-shame [filename]
72
(defn read-shame [filename]
73
  (json/read-str (slurp filename) :key-fn keyword))
73
  (json/decode (slurp filename) keyword))
74
74
75
(defn write-shame [filename shaming]
75
(defn write-shame [filename shaming]
76
  (spit filename (json/write-str shaming)))
76
  (spit filename (json/encode shaming)))
77
77
78
;; web service
78
;; web service
79
79