@Test public void testExtraFieldsAreIgnored() throws Exception { try { SimpletypesConfig.Builder builder = new SimpletypesConfig.Builder(); InnerCNode defWithExtra = new DefParser(SimpletypesConfig.CONFIG_DEF_NAME, new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n") + "\nnewfield string default=\"foo\"\n")).getTree(); InstanceResolver.applyDef(builder, defWithExtra); } catch (NoSuchFieldException e) { fail("Should not fail on extra field"); } }
static void applyDef(ConfigBuilder builder, InnerCNode targetDef) throws Exception { for (Map.Entry<String, CNode> e: targetDef.children().entrySet()) { CNode node = e.getValue(); if (node instanceof LeafCNode) { setLeafValueIfUnset(targetDef, builder, (LeafCNode)node); } else if (node instanceof InnerCNode) { if (hasField(builder.getClass(), node.getName())) { Field innerField = builder.getClass().getDeclaredField(node.getName()); innerField.setAccessible(true); Object innerFieldVal = innerField.get(builder); if (innerFieldVal instanceof List) { List<?> innerList = (List<?>) innerFieldVal; for (Object b : innerList) { if (b instanceof ConfigBuilder) { applyDef((ConfigBuilder) b, (InnerCNode) node); } } } else if (innerFieldVal instanceof ConfigBuilder) { applyDef((ConfigBuilder) innerFieldVal, (InnerCNode) node); } else { } } } } }
InstanceResolver { static void applyDef(ConfigBuilder builder, InnerCNode targetDef) throws Exception { for (Map.Entry<String, CNode> e: targetDef.children().entrySet()) { CNode node = e.getValue(); if (node instanceof LeafCNode) { setLeafValueIfUnset(targetDef, builder, (LeafCNode)node); } else if (node instanceof InnerCNode) { if (hasField(builder.getClass(), node.getName())) { Field innerField = builder.getClass().getDeclaredField(node.getName()); innerField.setAccessible(true); Object innerFieldVal = innerField.get(builder); if (innerFieldVal instanceof List) { List<?> innerList = (List<?>) innerFieldVal; for (Object b : innerList) { if (b instanceof ConfigBuilder) { applyDef((ConfigBuilder) b, (InnerCNode) node); } } } else if (innerFieldVal instanceof ConfigBuilder) { applyDef((ConfigBuilder) innerFieldVal, (InnerCNode) node); } else { } } } } } }
InstanceResolver { static void applyDef(ConfigBuilder builder, InnerCNode targetDef) throws Exception { for (Map.Entry<String, CNode> e: targetDef.children().entrySet()) { CNode node = e.getValue(); if (node instanceof LeafCNode) { setLeafValueIfUnset(targetDef, builder, (LeafCNode)node); } else if (node instanceof InnerCNode) { if (hasField(builder.getClass(), node.getName())) { Field innerField = builder.getClass().getDeclaredField(node.getName()); innerField.setAccessible(true); Object innerFieldVal = innerField.get(builder); if (innerFieldVal instanceof List) { List<?> innerList = (List<?>) innerFieldVal; for (Object b : innerList) { if (b instanceof ConfigBuilder) { applyDef((ConfigBuilder) b, (InnerCNode) node); } } } else if (innerFieldVal instanceof ConfigBuilder) { applyDef((ConfigBuilder) innerFieldVal, (InnerCNode) node); } else { } } } } }  }
InstanceResolver { static void applyDef(ConfigBuilder builder, InnerCNode targetDef) throws Exception { for (Map.Entry<String, CNode> e: targetDef.children().entrySet()) { CNode node = e.getValue(); if (node instanceof LeafCNode) { setLeafValueIfUnset(targetDef, builder, (LeafCNode)node); } else if (node instanceof InnerCNode) { if (hasField(builder.getClass(), node.getName())) { Field innerField = builder.getClass().getDeclaredField(node.getName()); innerField.setAccessible(true); Object innerFieldVal = innerField.get(builder); if (innerFieldVal instanceof List) { List<?> innerList = (List<?>) innerFieldVal; for (Object b : innerList) { if (b instanceof ConfigBuilder) { applyDef((ConfigBuilder) b, (InnerCNode) node); } } } else if (innerFieldVal instanceof ConfigBuilder) { applyDef((ConfigBuilder) innerFieldVal, (InnerCNode) node); } else { } } } } }   }
InstanceResolver { static void applyDef(ConfigBuilder builder, InnerCNode targetDef) throws Exception { for (Map.Entry<String, CNode> e: targetDef.children().entrySet()) { CNode node = e.getValue(); if (node instanceof LeafCNode) { setLeafValueIfUnset(targetDef, builder, (LeafCNode)node); } else if (node instanceof InnerCNode) { if (hasField(builder.getClass(), node.getName())) { Field innerField = builder.getClass().getDeclaredField(node.getName()); innerField.setAccessible(true); Object innerFieldVal = innerField.get(builder); if (innerFieldVal instanceof List) { List<?> innerList = (List<?>) innerFieldVal; for (Object b : innerList) { if (b instanceof ConfigBuilder) { applyDef((ConfigBuilder) b, (InnerCNode) node); } } } else if (innerFieldVal instanceof ConfigBuilder) { applyDef((ConfigBuilder) innerFieldVal, (InnerCNode) node); } else { } } } } }    }