Last active
December 23, 2015 19:39
-
-
Save takawitter/6684644 to your computer and use it in GitHub Desktop.
Java8 Lambda version of https://github.com/takawitter/jsonman#sample-code-2-finding-node .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.arnx.jsonic.JSON; | |
import org.jsonman.Node; | |
import org.jsonman.NodeFactory; | |
import org.jsonman.NodeFinder; | |
import org.jsonman.node.MapNode; | |
import org.junit.Assert; | |
import org.junit.Test; | |
public class NodeFinderTest{ | |
@Test | |
public void test_4() throws Exception{ | |
Node src = NodeFactory.create(JSON.decode( | |
"{\"people\":[{\"name\":\"john\",\"age\":20}," + | |
"{\"name\":\"bob\",\"age\":30}]}" | |
)); | |
new NodeFinder(src).find("/people[name=bob]", (path, node) -> { | |
Assert.assertTrue(node.isMap()); | |
MapNode mn = node.cast(); | |
Assert.assertEquals("bob", mn.getChildValue("name")); | |
Assert.assertEquals(30, ((Number)mn.getChildValue("age")).intValue()); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment