Transformer Doesn't Recursively Transform All Maps #558
-
I've written a value transformer to add the (def entity-transformer (mt/transformer {:decoders {:map {:compile (fn [schema _]
(fn [m]
(->> m
(et-id schema)
(et-type schema))))}}})) It works on the top-level map: (m/decode User {:name "Klay"} options entity-transformer)
{:name "Klay"
:id "FrMj"
:type :user} It doesn't work when the top-level datatype isn't a map: (m/decode User [{:name "Klay"} {:name "Kio"}] options entity-transformer)
; Execution error (IllegalArgumentException) at .../et-id (schema.clj:121).
; Key must be integer Or on nested maps where it isn't directly under a map, such as a vector: (m/decode User {:name "Klay"
:character [{:name "Adam"}
{:name "Eve"}]} options entity-transformer)
{:name "Klay"
:character [{:name "Adam"} {:name "Eve"}] ; No `:id` or `:type` on either maps.
:id "FrMj"
:type :user} Value transformations are advertised as supporting recursion, but that seems to only be true for simple schemas (integers, strings, etc.) Is there a way I could get the transformer to work on any map? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Nevermind, I made a few mistakes in my schema declarations. |
Beta Was this translation helpful? Give feedback.
Nevermind, I made a few mistakes in my schema declarations.
:character
should've been named:characters
. Top-level vectors still throw an error, but that's something that can be mitigated by transforming each separate value..