JsonPath implements Path<ReadContext, V> { @Override public V valueVia(ReadContext context) { return context.read(path); } JsonPath(String thePath, boolean hasLoopFlag, boolean denotesCollectionFlag); @Override V valueVia(ReadContext context); @Override Collection<V> valuesVia(ReadContext context); @Override boolean hasLoop(); @Override boolean denotesCollection(); @Override Path<ReadContext, V> withIndex(int segment, String index); @Override int depth();  }
@Test public void valueVia() { Person person = PeopleBuilder.newPerson("brian", "remedios", 123, new Date(), "a", "br"); String json = person.toString(); ReadContext context = com.jayway.jsonpath.JsonPath.parse(json); Path<ReadContext, Country> path = new JsonPath<Country>("$.passports[*].country", true, false); Collection<Country> results = path.valuesVia(context); for (Object item : results) { Assert.assertTrue(item instanceof String); } Path<ReadContext, String> path2 = new JsonPath<String>("$.passports[*].pages[*].contents", true, false); Collection<String> contents = path2.valuesVia(context); for (String item : contents) { Assert.assertTrue(item instanceof String); } }