如何使用 Jayway JsonPath 检查字段是否为空多于一个空格或为空

问题描述

如何检查一个字段是空的还是空的?在这种情况下,Empty 意味着它可以包含多个空格。

我试过这个,但它对我不起作用。我正在考虑使用正则表达式来检查多个空格。但我不能写。我是 Jayway JsonPath 的新手。请帮帮我。

String json = null;
Shipment shipment = new Shipment();
shipment.setTrackingNo("       "); // or shipment.setTrackingNo(null);
json = ObjectMapperFactory.getMapper().writeValueAsstring(shipment);
Object document = Configuration.defaultConfiguration().jsonProvider().parse(json);
List < Map < String,Object > > evaluationResult = JsonPath.read(document,"$[?(@.trackingNo==null || @.trackingNo==' ')].trackingNo");
if (!ObjectUtils.isEmpty(evaluationResult)) {
    System.out.println("match");
} else {
    System.out.println("not match");
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)