Fork me on GitHub
#malli
<
2021-06-04
>
ingesol15:06:36

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"}

datran17:06:21

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?

2
ikitommi17:06:26

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

ikitommi17:06:11

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

ingesol19:06:25

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

ingesol19:06:58

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

ingesol19:06:16

Aaaand it works! Thanks for great help, as always