@Test public void testSizeForNullNode() throws Exception { Assert.assertEquals(0, JsonUtils.size(null)); }
public static int size(JsonNode node) { if (node == null) { return 0; } int size = 0; if (node instanceof ArrayNode) { for (Iterator<JsonNode> elements = ((ArrayNode) node).elements(); elements.hasNext();) { size += size(elements.next()); } } else if (node instanceof ObjectNode) { for (Iterator<Map.Entry<String, JsonNode>> fields = ((ObjectNode) node).fields(); fields.hasNext();) { Map.Entry<String, JsonNode> field = fields.next(); size += field.getKey().length(); size += size(field.getValue()); } } else if (node instanceof NumericNode) { size += 4; } else { size += node.asText().length(); } return size; }
JsonUtils { public static int size(JsonNode node) { if (node == null) { return 0; } int size = 0; if (node instanceof ArrayNode) { for (Iterator<JsonNode> elements = ((ArrayNode) node).elements(); elements.hasNext();) { size += size(elements.next()); } } else if (node instanceof ObjectNode) { for (Iterator<Map.Entry<String, JsonNode>> fields = ((ObjectNode) node).fields(); fields.hasNext();) { Map.Entry<String, JsonNode> field = fields.next(); size += field.getKey().length(); size += size(field.getValue()); } } else if (node instanceof NumericNode) { size += 4; } else { size += node.asText().length(); } return size; } }
JsonUtils { public static int size(JsonNode node) { if (node == null) { return 0; } int size = 0; if (node instanceof ArrayNode) { for (Iterator<JsonNode> elements = ((ArrayNode) node).elements(); elements.hasNext();) { size += size(elements.next()); } } else if (node instanceof ObjectNode) { for (Iterator<Map.Entry<String, JsonNode>> fields = ((ObjectNode) node).fields(); fields.hasNext();) { Map.Entry<String, JsonNode> field = fields.next(); size += field.getKey().length(); size += size(field.getValue()); } } else if (node instanceof NumericNode) { size += 4; } else { size += node.asText().length(); } return size; } private  JsonUtils(); }
JsonUtils { public static int size(JsonNode node) { if (node == null) { return 0; } int size = 0; if (node instanceof ArrayNode) { for (Iterator<JsonNode> elements = ((ArrayNode) node).elements(); elements.hasNext();) { size += size(elements.next()); } } else if (node instanceof ObjectNode) { for (Iterator<Map.Entry<String, JsonNode>> fields = ((ObjectNode) node).fields(); fields.hasNext();) { Map.Entry<String, JsonNode> field = fields.next(); size += field.getKey().length(); size += size(field.getValue()); } } else if (node instanceof NumericNode) { size += 4; } else { size += node.asText().length(); } return size; } private  JsonUtils(); static ObjectMapper getObjectMapper(); static JsonNode json(String s); static JsonNode json(String s, boolean systemPropertySubstitution); static JsonNode json(InputStream stream, boolean systemPropertySubstitution); static JsonNode json(InputStream stream); static JsonNode json(Reader reader); static JsonNode json(Reader reader, boolean systemPropertySubstitution); static Object valueFromJson(ValueNode node); static ValueNode valueToJson(Object value); static Object fromJson(JsonNode json); static JsonNode toJson(Object obj); static String prettyPrint(JsonNode node); static void prettyPrint(StringBuilder bld, JsonNode node); static String toJson(String[] strings); static JsonSchema loadSchema(String resourceName); static String jsonSchemaValidation(JsonSchema schema, JsonNode node); static int size(JsonNode node); }
JsonUtils { public static int size(JsonNode node) { if (node == null) { return 0; } int size = 0; if (node instanceof ArrayNode) { for (Iterator<JsonNode> elements = ((ArrayNode) node).elements(); elements.hasNext();) { size += size(elements.next()); } } else if (node instanceof ObjectNode) { for (Iterator<Map.Entry<String, JsonNode>> fields = ((ObjectNode) node).fields(); fields.hasNext();) { Map.Entry<String, JsonNode> field = fields.next(); size += field.getKey().length(); size += size(field.getValue()); } } else if (node instanceof NumericNode) { size += 4; } else { size += node.asText().length(); } return size; } private  JsonUtils(); static ObjectMapper getObjectMapper(); static JsonNode json(String s); static JsonNode json(String s, boolean systemPropertySubstitution); static JsonNode json(InputStream stream, boolean systemPropertySubstitution); static JsonNode json(InputStream stream); static JsonNode json(Reader reader); static JsonNode json(Reader reader, boolean systemPropertySubstitution); static Object valueFromJson(ValueNode node); static ValueNode valueToJson(Object value); static Object fromJson(JsonNode json); static JsonNode toJson(Object obj); static String prettyPrint(JsonNode node); static void prettyPrint(StringBuilder bld, JsonNode node); static String toJson(String[] strings); static JsonSchema loadSchema(String resourceName); static String jsonSchemaValidation(JsonSchema schema, JsonNode node); static int size(JsonNode node);  }