Permalink
Browse files

make cheshire an optional dependency

you should only need it if you are using json configs
  • Loading branch information...
1 parent bb2bff9 commit eae079f4bfd1a0d50a75b11cd0f23ca73ec81797 @joegallo joegallo committed Dec 13, 2012
Showing with 15 additions and 3 deletions.
  1. +15 −3 src/carica/core.clj
View
@@ -1,8 +1,20 @@
(ns carica.core
(:use [clojure.java.io :only [reader]])
(:require [clojure.tools.logging :as log]
- [clojure.walk :as walk]
- [cheshire.core :as json]))
+ [clojure.walk :as walk]))
+
+(def json-enabled?
+ (try
+ (require 'cheshire.core)
+ true
+ (catch Throwable _
+ false)))
+
+(defn ^:dynamic json-parse-stream
+ "Resolve and apply cheshire's json parsing dynamically."
+ [& args]
+ {:pre [json-enabled?]}
+ (apply (ns-resolve (symbol "cheshire.core") (symbol "parse-stream")) args))
(defn resources
"Search the classpath for resources matching the given path"
@@ -39,7 +51,7 @@
(defmethod load-config "json" [resource]
(with-open [s (.openStream resource)]
- (-> s reader (json/parse-stream true))))
+ (-> s reader (json-parse-stream true))))
(defn get-configs
"Takes a data structure of config resources (URLs) in priority order and

0 comments on commit eae079f

Please sign in to comment.