ElementCloner { public Element cloneElement(final Element element, final Schema schema) { try { final Element clone = element.emptyClone(); final SchemaElementDefinition sed = schema.getElement(clone.getGroup()); for (final String propertyName : element.getProperties().keySet()) { final Object property = element.getProperty(propertyName); if (null == sed.getPropertyTypeDef(propertyName) || null == sed.getPropertyTypeDef(propertyName).getSerialiser()) { LOGGER.warn("Can't find Serialisation for {}, returning uncloned property", propertyName); clone.putProperty(propertyName, property); } else if (null != property) { final Serialiser serialiser = sed.getPropertyTypeDef(propertyName).getSerialiser(); clone.putProperty(propertyName, serialiser.deserialise(serialiser.serialise(property))); } else { clone.putProperty(propertyName, null); } } return clone; } catch (final SerialisationException e) { throw new RuntimeException("SerialisationException converting elements", e); } }  Element cloneElement(final Element element, final Schema schema);  }
@Test public void testElementCloner() throws StoreException { final ElementCloner cloner = new ElementCloner(); final MapStore mapStore = new MapStore(); mapStore.initialise("graphId", GetAllElementsHandlerTest.getSchema(), new MapStoreProperties()); Streams.toStream(GetAllElementsHandlerTest.getElements()) .map(element -> new Pair<>(element, cloner.cloneElement(element, mapStore.getSchema()))) .forEach(pair -> assertEquals(pair.getFirst(), pair.getSecond())); }