GeneralUtils { public static JsonNode getFirstMatchingNode(JsonNode parent, String... keys) { for (String key : keys) { JsonNode node = parent.path(key); if (!node.isMissingNode()) { return node; } } return Constants.MISSING_NODE; } private  GeneralUtils(); static long toPositiveLong(CharSequence seq, int pos, int length); static Decimal nodeToDecimal(JsonNode node); static BigDecimal nodeToBigDecimal(JsonNode node); static JsonNode executeTemplate(Context ctx, Instruction inst, JsonNode node, boolean privateContext); static JsonNode executeTemplate(Context ctx, Instruction inst, JsonNode node, boolean privateContext,
        ObjectNode argvar); static String loadResource(Class<?> cls, String path); static List<Path> listResources(Class<?> cls, String pattern); static V getOrDefault(Map<K, V> map, K key, V defaultValue); static String localizeOrDefault(JsonNode localizedStrings, String key, String defaultValue); static boolean isJsonStart(String raw); static JsonNode getFirstMatchingNode(JsonNode parent, String... keys); static String jsonPretty(JsonNode node); static Object[] splitVariable(String name); static String urlEncode(String val); static boolean isTruthy(JsonNode node); static String ifString(JsonNode node, String defaultString); static double ifDouble(JsonNode node, double defaultValue); static String eatNull(JsonNode node);  }
@Test public void testGetFirstMatchingNode() { ObjectNode o1 = JsonUtils.createObjectNode(); o1.put("foo", "bar"); ObjectNode o2 = JsonUtils.createObjectNode(); o2.set("obj", o1); assertEquals(GeneralUtils.getFirstMatchingNode(o2, "bar", "obj", "foo"), o1); assertEquals(GeneralUtils.getFirstMatchingNode(o2, "x", "y"), Constants.MISSING_NODE); }