Problems switching to Muuntaja from Ring

I was hoping for Muuntaja to be a simple drop-in replacement for ring.middleware wrap-formats, but it has been a week of running my head into apparent dependency errors. Even when I trace through lein deps :tree to remove dependencies with old versions of jsonista, my errors don’t seem to go away. Here’s the error:

error in process sentinel: Could not start nREPL server: Exception in thread “main” java.lang.ExceptionInInitializerError at clojure.main.(main.java:20)

Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/exc/InputCoercionException, compiling:(jsonista/core.clj:79:38)

In the new-project case in which I can actually get the repl to start, shortly after I try to evaluate my Muuntaja buffers I start getting “no REPL connected” errors.

(ns hmeg.middleware
  (:require [muuntaja.middleware :refer [wrap-format wrap-params]]))
;; ... other stuff ...
(defn wrap-formats [handler]
  (let [wrapped (-> handler wrap-params wrap-format)]
    (fn [request]
      ((if (:websocket? request) handler wrapped) request))))

;;;;;;;;;;;;;;;;;;
(ns hmeg.handler
  (:require [compojure.core :refer [routes wrap-routes]]
	    [hmeg.layout :refer [error-page]]
	    [hmeg.routes.home :refer [home-routes]]
	    [hmeg.routes.admin :as admin]
	    [compojure.route :as route]
	    [ring.util.http-response :as response]
	    [ring.middleware.format-params :as mformat]
	    [hmeg.env :refer [defaults]]
	    [mount.core :as mount]
	    [hmeg.middleware :as middleware]))

(defn app-routes []
  (routes
   (-> #'home-routes
       (wrap-routes middleware/wrap-formats))
   (-> #'admin/routes
       (wrap-routes middleware/wrap-formats))
   (route/not-found
    (:body
     (error-page {:status 404
		  :title "page not found"})))))

(defn app [] (middleware/wrap-base (app-routes)))

Any ideas?

This might be related to some other dep bringing in Jackson before Jsonista (which is used by Muuntaja) does. @Miikka had a thread about issues with this some weeks ago. You could maybe try to “move up” Muuntaja in your deps list, and see if that helps (also, you might want to check if different versions are used with @alexmiller 's graph tool for tools.deps) .

Does the order of the dependency list actually matter?

Yes, it does. @alexmiller talked quite a bit about this in the Conj.

Related discussion: Depending on the right versions of Jackson libraries

1 Like

Yes, the problem is most likely a mismatch in the versions of jackson-core and jackson-databind. I wrote a FAQ for jsonista about this. Basically the solution is to ensure that you have the same versions for both the Jackson libraries in your dependencies:

[com.fasterxml.jackson.core/jackson-core "2.10.2"]
[com.fasterxml.jackson.core/jackson-databind "2.10.2"]
2 Likes