JcrPersistenceAdapter implements PersistenceAdapter { @Override public CollectionResult getCollection(CollectionMapping collectionMapping) { try { final List<String> paths = new LinkedList<String>(); final String location = collectionMapping.getLocation(); if (node.hasNode(location)) { final Node collectionContainer = node.getNode(location); LOGGER.debug("Retrieving from node {}", collectionContainer.getPath()); for (final NodeIterator ni = collectionContainer.getNodes(); ni.hasNext();) { final Node child = ni.nextNode(); if (child.getName().equals("jcr:content")) { continue; } LOGGER.trace("Adding {} to collection.", child.getPath()); paths.add(child.getPath()); } } else if (node.hasProperty(location) && node.getProperty(location).isMultiple()) { final Property property = node.getProperty(location); LOGGER.debug("Retrieving from property {}", property.getPath()); for (final Value v : property.getValues()) { paths.add(v.getString()); } } else { return new MissingCollectionPersistenceResult(); } return new ImmutableCollectionPersistenceResult(paths); } catch (final RepositoryException e) { throw new ObjectMapperException("Could not retrieve collection from " + collectionMapping.getLocation()); } } JcrPersistenceAdapter(EntityMapping entityMapping, Node node); @Override void delete(); @Override CollectionResult getCollection(CollectionMapping collectionMapping); @Override String getId(); @Override MapResult getMapResult(CollectionMapping collectionMapping); @Override PersistenceResult getProperty(PersistenceRequest request); @Override PersistenceResult getProperty(PropertyMapping propertyMapping); @Override Object resolve(String path); @Override void setProperty(PropertyMapping propertyMapping, Object object);  }
@Test public void testGetCollection() throws Exception { final Node node = JcrUtils.getOrAddNode(jcrSession.getRootNode(), "foo"); node.addNode("a").setProperty("value", "value a"); node.addNode("b").setProperty("value", "value b"); node.addNode("c").setProperty("value", "value c"); final EntityMapping entityMapping = extractor.extract(CollectionTestEntity.class); final JcrPersistenceAdapter adapter = new JcrPersistenceAdapter(entityMapping, node); final CollectionResult result = adapter.getCollection((CollectionMapping) entityMapping.getByFieldName("listWithDifferingTargetAndImplType").getMapping()); assertThat(result, notNullValue()); final Collection<?> collection = result.getValue(); assertThat(collection, notNullValue()); assertThat(collection.size(), is(3)); }