java - 基于 JSON 的 Java 规则评估器
问题描述
我想开发一个 JSON 规则模式和一个规则评估器,我可以在其中定义和/或/或用于属性比较的单个条件的条件。例如 - 如果 customerType 是 PRIMARY 并且 locale 是 en-US,则以下规则将评估为 true。我计划用 Java 编写我的自定义规则评估器,它将规则 JSON 作为输入以及请求参数,并根据其匹配与否评估为真或假。我保持我的模式通用并为扩展开放。就像如果你想在将来支持“OR”条件,或者如果你想在将来支持像 ">=" 这样的运算符,你可以通过扩展你的规则评估器来做到这一点。有没有更好的方法来做到这一点?我的架构足够灵活吗?
"rule": {
"type": "CompositeRule",
"allOf": [ #In future, we can also support "anyOf" if required
{
"type": "SimpleRule",
"attribute": "customerType",
"operator": "==", #In future, we can also support other operators like ">=" or "<=" etc.
"value": "PRIMARY" #Value can be a number, string or boolean
},
{
"type": "SimpleRule",
"attribute": "locale",
"operator": "==",
"value": "en-US"
}
]
}
解决方案
推荐阅读
- javascript - JavaScript:如果字段已填充,则启用按钮不是自动的
- android - 如何在 android xml 可视化工具的父垂直线性布局中包含子水平线性布局?
- service-fabric-stateful - 从 StateManager 正确初始化 ReliableCollection
- css - ChartJS v2.6.0 在 Internet Explorer 中的意外行为
- arduino - 如何将图像从飞行无人机获取到手机或云端
- c# - 锁定静态锁定对象
- opentok - 如何制作 OpenTok 视频聊天的截图?
- perl - 使用替换从perl中的字符串中删除重复字符
- java - java -PDFBox 如何从文档中提取文本而不存储在数组中?
- html - 如何找到一个以“document.querySelectorAll”开头并以“document.querySelectorAll”结尾的元素?