使用 prismatic/schema 时,defrecord 上的枚举验证不起作用,如下所示:
(s/defrecord Action [type :- (s/enum :a :b)])
#'user/strict-map->Action
user> (Action. "3") ; this should fail
#user.Action{:type "3"}
user> (Action. 1) ; this should fail
#user.Action{:type 1}
user> (Action. "abc") ; this should fail
#user.Action{:type "abc"}
但是,当我将 enum 更改为 long 时,它按预期工作:
(s/defrecord ThisWorks [type :- long])
#'user/strict-map->ThisWorks
user> (ThisWorks. 3)
#user.ThisWorks{:type 3}
user> (ThisWorks. "abc")
ClassCastException java.lang.String cannot be cast to java.lang.Number user/eval11888 (form-init4803894880546699153.clj:1)
有人知道吗?太感谢了。