1

我正在尝试使用 aws-sdk-java 提供的 Java JmesParser(我尝试过 v1,现在尝试过 v2)。

使用来自 JmesPath 网站的测试数据,我使用以下 JSON 作为我的inputValue

{
  "locations": [
    {"name": "Seattle", "state": "WA"},
    {"name": "New York", "state": "NY"},
    {"name": "Bellevue", "state": "WA"},
    {"name": "Olympia", "state": "WA"}
  ]
}

并将以下字符串作为我的 JMESPath expression

locations[?state == 'WA'].name

然后我有以下Java:

Expression expression = JmesPathParser.parse(expression);
JmesPathAcceptorGenerator generator = new JmesPathAcceptorGenerator(ClassName.get(model.getMetadata().getFullWaitersInternalPackageName(),
            WaitersRuntimeGeneratorTask.RUNTIME_CLASS_NAME));
generator.interpret(expression, inputValue);

最后一行返回以下内容:

{
  "locations": [
    {"name": "Seattle", "state": "WA"},
    {"name": "New York", "state": "NY"},
    {"name": "Bellevue", "state": "WA"},
    {"name": "Olympia", "state": "WA"}
  ]
}.field("locations").filter(x0 -> x0.field("state").compare("==", x0.constant("WA"))).field("name")

我假设这.field()是我需要以某种方式评估以返回结果的添加部分,但我似乎找不到任何方法来做到这一点。如何让它对我的 JSON 实际运行过滤器并返回结果?

4

0 回答 0