Fork me on GitHub
#reitit
<
2022-10-24
>
tstirrat22:10:30

i'm trying to figure out spec-based transforms based on spec-tools. i've got a strict-json-transformer defined that looks like this:

(def strict-json-transformer
  (st/type-transformer
   st/json-transformer
   st/strip-extra-keys-transformer
   st/strip-extra-values-transformer))
and a spec defined like this:
(s/def ::information (st/spec {:spec (s/nilable ::app/information)
                               :decode/json #(or %2 "")}))
where the idea is that the frontend sometimes sends null for a value that isn't nullable, and i'm dealing with it on the backend. when I do:
(st/decode ::information nil strict-json-transformer)
i'd expect to get a "", but that doesn't seem to be happening, and I'm having a hell of a time tracing the source to understand where i might be going wrong. any pointers?

tstirrat16:10:23

i figured this out by calling (st/-name strict-json-transformer) to get the name that it identifies itself by. turns out that because type-transformer is doing a left-to-right merge of all of the provided transformers, it calls itself a value-transformer, and when i did decode/value-transformer (or whatever the name was) it started working.