Source:
private static void copyFields(Fields dest, Fields source, MutablePath path, CompositeMetadata parentEntity, GetMetadata gmd) { for (Iterator<Field> itr = source.getFields(); itr.hasNext();) { Field field = itr.next(); Error.push(field.getName()); path.push(field.getName()); LOGGER.debug("Processing {}", path); try { if (field instanceof SimpleField) { SimpleField newField = new SimpleField(field.getName(), field.getType()); newField.shallowCopyFrom(field); dest.put(newField); } else if (field instanceof ObjectField) { ObjectField newField = new ObjectField(field.getName()); newField.shallowCopyFrom(field); copyFields(newField.getFields(), ((ObjectField) field).getFields(), path, parentEntity, gmd); dest.put(newField); } else if (field instanceof ArrayField) { ArrayElement sourceEl = ((ArrayField) field).getElement(); ArrayElement newElement; if (sourceEl instanceof ObjectArrayElement) { path.push(Path.ANY); newElement = new ObjectArrayElement(); copyFields(((ObjectArrayElement) newElement).getFields(), ((ObjectArrayElement) sourceEl).getFields(), path, parentEntity, gmd); path.pop(); } else { newElement = new SimpleArrayElement(((SimpleArrayElement) sourceEl).getType()); ((SimpleArrayElement)newElement).setConstraints( ((SimpleArrayElement)sourceEl).getConstraints()); LOGGER.debug("Constraints:{}",((SimpleArrayElement)newElement).getConstraints()); } newElement.getProperties().putAll(sourceEl.getProperties()); ArrayField newField = new ArrayField(field.getName(), newElement); newField.shallowCopyFrom(field); dest.put(newField); } else { ReferenceField reference = (ReferenceField) field; ResolvedReferenceField newField = resolveReference(reference, path, parentEntity, gmd); if (newField != null) { dest.put(newField); } } } finally { Error.pop(); } path.pop(); } }

Target:
private static void copyFields(Fields dest, Fields source, MutablePath path, CompositeMetadata parentEntity, GetMetadata gmd) { for (Iterator<Field> itr = source.getFields(); itr.hasNext();) { Field field = itr.next(); Error.push(field.getName()); path.push(field.getName()); LOGGER.debug("Processing {}", path); try { if (field instanceof SimpleField) { SimpleField newField = new SimpleField(field.getName(), field.getType()); newField.shallowCopyFrom(field); dest.put(newField); } else if (field instanceof ObjectField) { ObjectField newField = new ObjectField(field.getName()); newField.shallowCopyFrom(field); copyFields(newField.getFields(), ((ObjectField) field).getFields(), path, parentEntity, gmd); dest.put(newField); } else if (field instanceof ArrayField) { ArrayElement sourceEl = ((ArrayField) field).getElement(); ArrayElement newElement; if (sourceEl instanceof ObjectArrayElement) { path.push(Path.ANY); newElement = new ObjectArrayElement(); copyFields(((ObjectArrayElement) newElement).getFields(), ((ObjectArrayElement) sourceEl).getFields(), path, parentEntity, gmd); path.pop(); } else { SimpleArrayElement simpleElement=new SimpleArrayElement(((SimpleArrayElement) sourceEl).getType()); simpleElement.setConstraints(((SimpleArrayElement)sourceEl).getConstraints()); LOGGER.debug("Constraints:{}",simpleElement.getConstraints()); newElement=simpleElement; } newElement.getProperties().putAll(sourceEl.getProperties()); ArrayField newField = new ArrayField(field.getName(), newElement); newField.shallowCopyFrom(field); dest.put(newField); } else { ReferenceField reference = (ReferenceField) field; ResolvedReferenceField newField = resolveReference(reference, path, parentEntity, gmd); if (newField != null) { dest.put(newField); } } } finally { Error.pop(); } path.pop(); } }