我需要验证从json字符串转换的clojure贴图的形状.json字符串是我正在实现的协议的消息.为此,我正在尝试clojure.spec.alpha.
我正在使用s /键.我的协议中的多个消息具有相同的密钥名称,但这些密钥附加了不同形状的值,因此无法通过相同的规范进行验证.
一个例子:
;; Here status should have the same key name, but their shape
;; is different. But definining another spec forces me to register it with a
;; different keyword, which breaks the "should have name 'status'" requirement.
(s/def ::a-message
(s/keys :req [::status]))
(s/def ::another-message
(s/keys :req [::status]))
Run Code Online (Sandbox Code Playgroud)
我想我可以在不同的命名空间中定义:status spec,但这对我来说似乎有些过分.毕竟它只是在同一协议中的不同消息,我只是有几个冲突.
(s /键)是否有办法将正在检查其存在的密钥的名称与正在验证它的规范的名称分开?
我的情况是:
我理解vert.x事件总线的范围比我的用例要广泛得多.
我想到了一个类似于akka的行为:当你分发时,你必须为你的消息提供序列化,如果你保持本地引用被传递.
有没有什么可以让我在Vert.x中做到这一点?