@Test public void testDocModify_ovrLength() throws Exception { JsonNodeFactory factory = JsonNodeFactory.withExactBigDecimals(false); ObjectNode node = factory.objectNode(); JsonDoc doc = new JsonDoc(node); ObjectNode obj1; node.put("obj1", obj1 = factory.objectNode()); node.put("simpleString", factory.textNode("str")); ArrayNode a1; obj1.put("simpleArr", a1 = factory.arrayNode()); a1.add(factory.textNode("a")); ObjectNode o; obj1.put("nested", o = factory.objectNode()); ArrayNode a2; o.put("objArr", a2 = factory.arrayNode()); o.put("objArr#", factory.numberNode(100)); a2.add(factory.objectNode()); PredefinedFields.updateArraySizes(getMD2(), factory, doc); System.out.println(doc); Assert.assertNotNull(doc.get(new Path("obj1.simpleArr"))); Assert.assertNull(doc.get(new Path("obj1.simpleArr#"))); Assert.assertEquals(1, doc.get(new Path("obj1.nested.objArr#")).intValue()); }
public static void updateArraySizes(EntityMetadata md, JsonNodeFactory factory, JsonDoc doc) { FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode f = cursor.getCurrentNode(); if (doesFieldNameMatchArrayCountPattern(f.getName())) { Path lengthField = cursor.getCurrentPath(); String ls = lengthField.toString(); Path arrField = new Path(ls.substring(0, ls.length() - 1)); try { if (md.resolve(arrField) != null) { JsonNode arrNode = doc.get(arrField); if (arrNode == null || arrNode instanceof NullNode) { doc.modify(lengthField, factory.numberNode(0), false); } else { doc.modify(lengthField, factory.numberNode(arrNode.size()), false); } } } catch (Exception e) { } } } }
PredefinedFields { public static void updateArraySizes(EntityMetadata md, JsonNodeFactory factory, JsonDoc doc) { FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode f = cursor.getCurrentNode(); if (doesFieldNameMatchArrayCountPattern(f.getName())) { Path lengthField = cursor.getCurrentPath(); String ls = lengthField.toString(); Path arrField = new Path(ls.substring(0, ls.length() - 1)); try { if (md.resolve(arrField) != null) { JsonNode arrNode = doc.get(arrField); if (arrNode == null || arrNode instanceof NullNode) { doc.modify(lengthField, factory.numberNode(0), false); } else { doc.modify(lengthField, factory.numberNode(arrNode.size()), false); } } } catch (Exception e) { } } } } }
PredefinedFields { public static void updateArraySizes(EntityMetadata md, JsonNodeFactory factory, JsonDoc doc) { FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode f = cursor.getCurrentNode(); if (doesFieldNameMatchArrayCountPattern(f.getName())) { Path lengthField = cursor.getCurrentPath(); String ls = lengthField.toString(); Path arrField = new Path(ls.substring(0, ls.length() - 1)); try { if (md.resolve(arrField) != null) { JsonNode arrNode = doc.get(arrField); if (arrNode == null || arrNode instanceof NullNode) { doc.modify(lengthField, factory.numberNode(0), false); } else { doc.modify(lengthField, factory.numberNode(arrNode.size()), false); } } } catch (Exception e) { } } } } private  PredefinedFields(); }
PredefinedFields { public static void updateArraySizes(EntityMetadata md, JsonNodeFactory factory, JsonDoc doc) { FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode f = cursor.getCurrentNode(); if (doesFieldNameMatchArrayCountPattern(f.getName())) { Path lengthField = cursor.getCurrentPath(); String ls = lengthField.toString(); Path arrField = new Path(ls.substring(0, ls.length() - 1)); try { if (md.resolve(arrField) != null) { JsonNode arrNode = doc.get(arrField); if (arrNode == null || arrNode instanceof NullNode) { doc.modify(lengthField, factory.numberNode(0), false); } else { doc.modify(lengthField, factory.numberNode(arrNode.size()), false); } } } catch (Exception e) { } } } } private  PredefinedFields(); static void ensurePredefinedFields(EntityMetadata md); static void updateArraySizes(EntityMetadata md, JsonNodeFactory factory, JsonDoc doc); static boolean isFieldObjectType(String fieldName); static boolean isFieldAnArrayCount(String fieldName, Fields metadataFields); static boolean isPredefinedField(String fieldName, Fields fields); static String createArrayFieldNameFromCountField(String countField); static String createArrayCountFieldName(String arrayFieldName); }
PredefinedFields { public static void updateArraySizes(EntityMetadata md, JsonNodeFactory factory, JsonDoc doc) { FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode f = cursor.getCurrentNode(); if (doesFieldNameMatchArrayCountPattern(f.getName())) { Path lengthField = cursor.getCurrentPath(); String ls = lengthField.toString(); Path arrField = new Path(ls.substring(0, ls.length() - 1)); try { if (md.resolve(arrField) != null) { JsonNode arrNode = doc.get(arrField); if (arrNode == null || arrNode instanceof NullNode) { doc.modify(lengthField, factory.numberNode(0), false); } else { doc.modify(lengthField, factory.numberNode(arrNode.size()), false); } } } catch (Exception e) { } } } } private  PredefinedFields(); static void ensurePredefinedFields(EntityMetadata md); static void updateArraySizes(EntityMetadata md, JsonNodeFactory factory, JsonDoc doc); static boolean isFieldObjectType(String fieldName); static boolean isFieldAnArrayCount(String fieldName, Fields metadataFields); static boolean isPredefinedField(String fieldName, Fields fields); static String createArrayFieldNameFromCountField(String countField); static String createArrayCountFieldName(String arrayFieldName); static final String OBJECTTYPE_FIELD; static final String FIELD_ARRAY_COUNT_POSTFIX; static final Path OBJECTTYPE_PATH; }