我有一个简单的json有效载荷。我想在此添加一个筛选条件,以检查是否(模式==‘定制’和lastUpdatedDate - createdDate >= 180000)。
有人能帮我处理一下过滤器的状况吗。
{
"id":"1664437560",
"mode":"CUSTOM",
"createdDate":1664437561000,
"lastUpdatedDate":1664437620256,
"customerIdentifier":"8a9fcc828",
"status":"Success"
}
我对jsonpath很熟悉,但是找不到一种使用+/-/*运算符的过滤条件的方法。我还尝试在求和函数上添加过滤条件,这也不起作用。
发布于 2022-09-29 05:22:41
乔森图书馆能做好这份工作。
https://github.com/octomix/josson
反序列化
Josson josson = Josson.fromJsonString(
"{" +
" \"id\":\"1664437560\"," +
" \"mode\":\"CUSTOM\"," +
" \"createdDate\":1664437561000," +
" \"lastUpdatedDate\":1664437620256," +
" \"customerIdentifier\":\"8a9fcc828\"," +
" \"status\":\"Success\"" +
"}");
查询
JsonNode node = josson.getNode("[mode='CUSTOM' & calc(lastUpdatedDate - createdDate) >= 180000]");
System.out.println(node == null ? null : node.toPrettyString());
输出
null
反序列化(将lastUpdatedDate
更改为1664437861000
)
Josson josson = Josson.fromJsonString(
"{" +
" \"id\":\"1664437560\"," +
" \"mode\":\"CUSTOM\"," +
" \"createdDate\":1664437561000," +
" \"lastUpdatedDate\":1664437861000," +
" \"customerIdentifier\":\"8a9fcc828\"," +
" \"status\":\"Success\"" +
"}");
查询
JsonNode node = josson.getNode("[mode='CUSTOM' & calc(lastUpdatedDate - createdDate) >= 180000]");
System.out.println(node == null ? null : node.toPrettyString());
输出
{
"id" : "1664437560",
"mode" : "CUSTOM",
"createdDate" : 1664437561000,
"lastUpdatedDate" : 1664437861000,
"customerIdentifier" : "8a9fcc828",
"status" : "Success"
}
https://stackoverflow.com/questions/73895389
复制