This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-15
Channels
- # announcements (7)
- # aws (30)
- # beginners (141)
- # boot-dev (3)
- # cider (48)
- # clara (35)
- # clojure (94)
- # clojure-europe (6)
- # clojure-italy (20)
- # clojure-nl (19)
- # clojure-norway (1)
- # clojure-portugal (6)
- # clojure-spec (7)
- # clojure-survey (3)
- # clojure-uk (93)
- # clojuredesign-podcast (22)
- # clojurescript (20)
- # core-async (54)
- # cursive (29)
- # datascript (1)
- # datomic (4)
- # emacs (2)
- # fulcro (10)
- # jobs (17)
- # juxt (3)
- # kaocha (20)
- # leiningen (20)
- # malli (22)
- # other-languages (7)
- # pedestal (4)
- # perun (2)
- # quil (2)
- # re-frame (7)
- # reagent (3)
- # reitit (31)
- # shadow-cljs (18)
- # spacemacs (11)
- # vim (32)
I want to use clojure.spec
to validate the input of a decimal?
data type. How can I extend the middlewares available to provide this? I know ring-json
seems to have an option to handle it
@iagwanderson for json? You need to configure Muuntaja->jsonista->Jackson to support that. Will paste few links in the thread
the setting: https://github.com/metosin/jsonista/blob/master/src/clj/jsonista/core.clj#L126
via Muuntaja: https://github.com/metosin/muuntaja/blob/master/README.md#configuration
imo way too hard currently, and there should be examples how to do this. Doc PR welcome!
(def m
(m/create
(assoc-in
m/default-options
[:formats "application/json" :decoder-opts :bigdecimals]
true)))
imo way too hard currently, and there should be examples how to do this. Doc PR welcome!
hello @ikitommi!! Yes, actually is too hard indeed rsrsrs I tried it yesterday for a while unsuccessfully rsrsrs I will check the links you provided
I got the gist of it, but there is something wrong with this new muuntaja instance. I did this experiment isolated to debug the problem:
(def m
(m/create
(assoc-in
m/default-options
[:formats "application/json" :decoder-opts :bigdecimals]
true)))
(require '[jsonista.core :as j])
(def mapper (j/object-mapper {:bigdecimals true}))
(-> "{\"kikka\": 32.2}"
(j/read-value mapper)
:kikka
class)
;; => java.math.BigDecimal
(->> "{\"kikka\": 32.2}"
(m/decode "application/json")
:kikka
class)
;; => java.lang.Double
cool, worked! but I keep getting error on the reitit though
"problems": [
{
"path": [
"y"
],
"pred": "clojure.core/decimal?",
"val": "10.0",
"via": [
"secland.services.web/math-request",
"secland.services.web/y"
],
"in": [
"y"
]
@iagwanderson you are using the default muuntaja here: https://github.com/wandersoncferreira/reitit-study/blob/master/src/reitit_study/core.clj#L59
I should pass only m
? because it is an instance of muuntaja. I just tried, and did not work either anyway.
https://github.com/metosin/spec-tools/blob/master/src/spec_tools/transform.cljc#L185
thanks!! I also open an issue asking for directions towards a string->ratio
implementation: https://github.com/metosin/spec-tools/issues/209
I will try to produce an image like this one to understand the inner workings of reitit:
@iagwanderson each route a it's unique middleware or interceptor-stack, optimized for that specific route (and other route data too) Otherwise, the pic looks right