malli

https://github.com/metosin/malli :malli:
ingesol 2021-06-04T15:27:36.098700Z

I’ve been trying to get this to work, but cannot figure out what is going on. I’m expecting the :type value to be converted to a string:

(m/encode
 [:schema {:registry
           {::node [:multi {:dispatch      :type
                            :decode/string #(update % :type keyword)}
                    [:malli.core/default
                     [:map
                      [:type :keyword]]]]}}
  ::node]
 {:type  :doc}
 mt/string-transformer)

=> {:type :doc}
If I replace :malli.core/default with :doc, I get the expected string-coerced keyword
{:type "doc"}
Also, the schema has a local registry in order to be able to have nodes within nodes. If I remove the wrapping, the following also works:
(m/encode
 [:map
  [:type :keyword]]
 {:type  :doc}
 mt/string-transformer)

=> {:type "doc"}

2021-06-04T17:23:21.100300Z

What's the difference between parsing data and decoding data? My sense is that parse is similar to spec's conform, whereas decode is more about transformation - is that generally right?

✅ 1
ikitommi 2021-06-04T17:39:26.100500Z

decoding is a process of transforming values from external formats into valid clojure data. Parsing returns the parse trees.

ikitommi 2021-06-04T17:44:11.100600Z

@ingesol what version are you using. CHANGELOG says it's fixed in 0.5.0

ikitommi 2021-06-04T17:44:35.100700Z

https://github.com/metosin/malli/issues/415

ingesol 2021-06-04T19:17:25.101Z

@ikitommi hmm, I thought I was on 0.5.2 or something, will check

ingesol 2021-06-04T19:23:58.101900Z

Very happy to be wrong, I was on 0.4.0. Thanks 🙂

ingesol 2021-06-04T19:29:16.102100Z

Aaaand it works! Thanks for great help, as always