Fork me on GitHub

Hi all! I have some nested routes like this:

      ["/" {... :name :home}]
      ["/*slugs" {... :name :page}]]
Where *slugs matches an arbitrarily nested route:
(reitit/match-by-path $router "/en/one/two")
;; {:template "/:lang/*slugs",
;;  :data {... :name :page},
;;  :result nil,
;;  :path-params {:slugs "one/two", :lang "en"},
;;  :path "/en/one/two"}
However, it URL-encodes the nested bit when I try to do reverse routing:
(reitit/match-by-name $router :page {:lang :en :slugs "one/two"})
;; {:template "/:lang/*slugs",
;;  :data
;;  {... :name :page},
;;  :result nil,
;;  :path-params {:lang "en", :slugs "one/two"},
;;  :path "/en/one%2Ftwo"}
Is there a way to disable/control the encoding?


or, alternatively, a better way to handle arbitrarily nested routes...?

wontheone105:03:20 Hello Good people of Metosin. I think testit had a nice idea. Can I ask why it became Deprecated status?


Hi, quick question that I’d love some help with. Consider the following code:

(require '[muuntaja.core :as mu])
(require '( [io :as io]))
(def new-muuntaja-instance
    (-> mu/default-options
          [:formats "application/json" :decoder-opts]
          {:bigdecimals true}))))

(->> (io/input-stream (.getBytes "{\"value\":100}"))
     (mu/decode new-muuntaja-instance "application/json")

(->> (io/input-stream (.getBytes "{\"value\":100.1}"))
     (mu/decode new-muuntaja-instance "application/json")
I have two simple decode functions that use muuntaja to decode a numeric value. I have configured :bigdecimals to true - which decodes doubles as bigdecimals. All well and good, except I would like all values (including ints) to be decoded to bigdecimals for this particular field (as it is 100.1 is a double -> decoded as a bigdecimal, 100 is an int -> decoded as an int). So you can understand my motivation, I am using a malli schema to validate my json, and this is failing validation for amounts that happen to not have a decimal place in my json (because they are being encoded as ints and I am expecting all values to be bigdecimals). Any idea on how I would ensure consistent bigdecimal encoding for numeric fields using muuntaja?


A possibility is to provider your own module


muuntaja uses jsonista under the hood, and one of the things it allows you to do is to provide a :modules key. You can define your own jacksondatabind module that would give you the behavior you want.


I think the approach would be to examine this:


notice lines 140-156


notice also how a custom jackson module is provided clojure-module.


You could do something similar


ALso, here is a so answer that may help too (which, although not related to clojure, would give you some insight on what you could try)


Thanks for the tips David, I’ll take a look at creating my own module and see how I get on


I hope it is useful 🙂


Good luck! 🙂


does anyone have any examples of applying a middleware (in my case format response as json) for a single route ?


this is what i tried but i get an error

(ring/router [["/foobar"
{:get {:responses  {200 {:body map?}}
       :handler    (constantly (response/ok {:data 123}))}
 :middleware [muuntaja/format-negotiate-middleware]}]
> HTTP ERROR 500 java.lang.IllegalArgumentException: No implementation of method: :write-body-to-stream of protocol: #'ring.core.protocols/StreamableResponseBody found for class: clojure.lang.PersistentArrayMap


This middleware does not format the response. It is only doing content negotiation. I think you need to include muuntaja/format-response-middleware. Or consider muuntaja/format-middleware which gets you negotiation, decoding, and encoding all bundled together.