-
Notifications
You must be signed in to change notification settings - Fork 222
Open
Labels
bugSomething isn't workingSomething isn't working
Description
It appears that malli.experimental.time.transform/time-transformer
encodes nil
values for schema [:maybe :time/duration]
as ""
empty strings:
(require '[malli.core :as ma]
'[malli.experimental.time :as met]
'[malli.experimental.time.transform :as mett]
'[malli.registry :as mr])
(mr/set-default-registry!
(mr/composite-registry
(ma/default-schemas)
(met/schemas)))
(ma/encode [:maybe :time/duration] nil mett/time-transformer)
;=> ""
I would expect that it preserves nil
values.
This is particularly problematic, since it can then not decode the ""
empty string value to an actual java.time.Duration
:
(ma/decode [:maybe :time/duration] "" mett/time-transformer)
;=> ""
And thus this also fails validation; sadly with a not very helpful explanation:
(require '[malli.error :as me])
(me/humanize (ma/explain [:maybe :time/duration] ""))
;=> ["unknown error"]
Compare that to:
(ma/decode [:maybe :time/duration] nil mett/time-transformer)
;=> nil
(ma/decode [:maybe :time/duration] "P1D" mett/time-transformer)
;=> #object[java.time.Duration 0x1ab268bd "PT24H"]
This appears similar to #1204.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
👍 Could do