Exemplo n.º 1
0
  @Test
  public void issue_29_b() throws Exception {
    String json =
        "{\"list\": [ { \"a\":\"atext\", \"b\":{ \"b-a\":\"batext\", \"b-b\":\"bbtext\" } }, { \"a\":\"atext2\", \"b\":{ \"b-a\":\"batext2\", \"b-b\":\"bbtext2\" } } ] }";
    List<String> result =
        read(json, "$.list[?]", Filter.filter(Criteria.where("b.b-a").eq("batext2")));

    assertTrue(result.size() == 1);
  }
Exemplo n.º 2
0
  // http://stackoverflow.com/questions/28596324/jsonpath-filtering-api
  @Test
  public void stack_overflow_question_1() {

    String json =
        "{\n"
            + "\"store\": {\n"
            + "    \"book\": [\n"
            + "        {\n"
            + "            \"category\": \"reference\",\n"
            + "            \"authors\" : [\n"
            + "                 {\n"
            + "                     \"firstName\" : \"Nigel\",\n"
            + "                     \"lastName\" :  \"Rees\"\n"
            + "                  }\n"
            + "            ],\n"
            + "            \"title\": \"Sayings of the Century\",\n"
            + "            \"price\": 8.95\n"
            + "        },\n"
            + "        {\n"
            + "            \"category\": \"fiction\",\n"
            + "            \"authors\": [\n"
            + "                 {\n"
            + "                     \"firstName\" : \"Evelyn\",\n"
            + "                     \"lastName\" :  \"Waugh\"\n"
            + "                  },\n"
            + "                 {\n"
            + "                     \"firstName\" : \"Another\",\n"
            + "                     \"lastName\" :  \"Author\"\n"
            + "                  }\n"
            + "            ],\n"
            + "            \"title\": \"Sword of Honour\",\n"
            + "            \"price\": 12.99\n"
            + "        }\n"
            + "    ]\n"
            + "  }\n"
            + "}";

    Filter filter = Filter.filter(Criteria.where("authors[*].lastName").contains("Waugh"));

    Object read = JsonPath.parse(json).read("$.store.book[?]", filter);

    System.out.println(read);
  }
Exemplo n.º 3
0
  @Test
  public void issue_129() throws Exception {

    final Map<String, Integer> match = new HashMap<String, Integer>();
    match.put("a", 1);
    match.put("b", 2);

    Map<String, Integer> noMatch = new HashMap<String, Integer>();
    noMatch.put("a", -1);
    noMatch.put("b", -2);

    Filter orig = filter(where("a").eq(1).and("b").eq(2));

    String filterAsString = orig.toString();

    Filter parsed = Filter.parse(filterAsString);

    assertThat(orig.apply(createPredicateContext(match))).isTrue();
    assertThat(parsed.apply(createPredicateContext(match))).isTrue();
    assertThat(orig.apply(createPredicateContext(noMatch))).isFalse();
    assertThat(parsed.apply(createPredicateContext(noMatch))).isFalse();
  }