GeneralUtils { public static String ifString(JsonNode node, String defaultString) { return isTruthy(node) ? node.asText() : defaultString; } 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 testIfString() { JsonNode node = new IntNode(123); assertEquals(GeneralUtils.ifString(node, "000"), "123"); node = new TextNode("456"); assertEquals(GeneralUtils.ifString(node, "000"), "456"); node = new IntNode(0); assertEquals(GeneralUtils.ifString(node, "000"), "000"); node = NullNode.getInstance(); assertEquals(GeneralUtils.ifString(node, "000"), "000"); }