diff --git a/src/ziggurat/middleware/json.clj b/src/ziggurat/middleware/json.clj index 372faa60..523d6b49 100644 --- a/src/ziggurat/middleware/json.clj +++ b/src/ziggurat/middleware/json.clj @@ -8,9 +8,9 @@ [ziggurat.metrics :as metrics])) (defn- deserialize-json - [message topic-entity-name key-fn encoding] + [message topic-entity-name key-fn] (try - (parse-string (String. message encoding) key-fn) + (parse-string message key-fn) (catch Exception e (let [additional-tags {:topic_name topic-entity-name} default-namespace "json-message-parsing"] @@ -39,9 +39,7 @@ " ([handler-fn topic-entity-name] - (parse-json handler-fn topic-entity-name true "UTF-8")) + (parse-json handler-fn topic-entity-name true)) ([handler-fn topic-entity-name key-fn] - (parse-json handler-fn topic-entity-name key-fn "UTF-8")) - ([handler-fn topic-entity-name key-fn encoding] (fn [message] - (handler-fn (deserialize-json message topic-entity-name key-fn encoding))))) + (handler-fn (deserialize-json message topic-entity-name key-fn))))) diff --git a/test/ziggurat/middleware/json_test.clj b/test/ziggurat/middleware/json_test.clj index 62170f62..0f1a009a 100644 --- a/test/ziggurat/middleware/json_test.clj +++ b/test/ziggurat/middleware/json_test.clj @@ -17,7 +17,7 @@ handler-fn (fn [msg] (if (= msg message) (reset! handler-fn-called? true)))] - ((parse-json handler-fn topic-entity-name) (.getBytes (generate-string message))) + ((parse-json handler-fn topic-entity-name) (generate-string message)) (is (true? @handler-fn-called?)))) (testing "Given a handler function and key-fn as false, parse-json should call that function on after deserializing the string without coercing the keys to keywords." @@ -29,19 +29,7 @@ handler-fn (fn [msg] (if (= msg expected-output) (reset! handler-fn-called? true)))] - ((parse-json handler-fn topic-entity-name false) (.getBytes (generate-string message))) - (is (true? @handler-fn-called?)))) - (testing "Given a handler function, key-fn as false and an encoding, parse-json should call that function on after - deserializing the string (with the given encoding) without coercing the keys to keywords." - (let [handler-fn-called? (atom false) - message {:a "A" - :b "B"} - expected-output {"a" "A" "b" "B"} - topic-entity-name "test" - handler-fn (fn [msg] - (if (= msg expected-output) - (reset! handler-fn-called? true)))] - ((parse-json handler-fn topic-entity-name false "UTF-8") (.getBytes (generate-string message))) + ((parse-json handler-fn topic-entity-name false) (generate-string message)) (is (true? @handler-fn-called?)))) (testing "Given a handler function and a key-fn, parse-json should call that function after deserializing the string by applying key-fn to keys." @@ -54,7 +42,7 @@ handler-fn (fn [msg] (if (= msg expected-output) (reset! handler-fn-called? true)))] - ((parse-json handler-fn topic-entity-name key-fn) (.getBytes (generate-string message))) + ((parse-json handler-fn topic-entity-name key-fn) (generate-string message)) (is (true? @handler-fn-called?)))) (testing "Should report metrics when JSON deserialization fails" (let [handler-fn-called? (atom false) @@ -66,6 +54,6 @@ (reset! handler-fn-called? true)))] (with-redefs [metrics/increment-count (fn [_ _ _] (reset! metric-reporter-called? true))] - ((parse-json handler-fn topic-entity-name true) (.getBytes message))) + ((parse-json handler-fn topic-entity-name true) message)) (is (true? @handler-fn-called?)) (is (true? @metric-reporter-called?)))))