@Override public void visit(String key, String value) { Key<?, ?> k = parseNamespacedKey(em, key, false); if (k == null) return; logger.trace("getAll(): considering " + value); if (type.isSuperclassOf(k.getEntityType())) { logger.trace(" --> correct type"); JSONObject candidate = JSONParser.parseStrict(value).isObject(); Assert.notNull(candidate); if (matcher.matches(candidate)) { @SuppressWarnings("unchecked") Key<X, ?> typedKey = (Key<X, ?>) k; // Unfortunately, this throws away a lot of work we've already done (getting the entity type, // creating the key, doing a backend.get(), parsing the JSON value, ...) // it would be nice to avoid this, but we have to go back to the entity manager in case the // thing we want is in the persistence context. entities.add((X) em.find(k.getEntityType().getJavaType(), typedKey.getId())); } else { logger.trace(" --> but not a match"); } } else { logger.trace(" --> wrong type"); } } });