CollectionExtractor implements Extractor { public Object extractObject(ObjectToJsonConverter pConverter, Object pValue, Stack<String> pPathParts, boolean jsonify) throws AttributeNotFoundException { Collection collection = (Collection) pValue; String pathPart = pPathParts.isEmpty() ? null : pPathParts.pop(); int length = pConverter.getCollectionLength(collection.size()); if (pathPart != null) { return extractWithPath(pConverter, collection, pPathParts, jsonify, pathPart, length); } else { return jsonify ? extractListAsJson(pConverter, collection, pPathParts, length) : collection; } }  Class getType(); Object extractObject(ObjectToJsonConverter pConverter, Object pValue, Stack<String> pPathParts, boolean jsonify); Object setObjectValue(StringToObjectConverter pConverter, Object pInner, String pAttribute, Object pValue); boolean canSetValue();  }
@Test public void jsonAndPath() throws AttributeNotFoundException { Collection collection = Arrays.asList("jolokia","habanero"); Stack paths = new Stack(); paths.add("1"); String val = (String) extractor.extractObject(converter,collection,paths,true); assertEquals(val, "habanero"); }
@Test public void jsonAndInvalidPaths() throws AttributeNotFoundException { Collection collection = Arrays.asList("jolokia","habanero"); for (String path : new String[] { "bla", "2"}) { Stack<String> paths = new Stack(); paths.add(path); try { extractor.extractObject(converter, collection, paths, true); fail(); } catch (AttributeNotFoundException exp) { } } }
@Test public void noJson() throws AttributeNotFoundException { Set set = new HashSet(Arrays.asList("jolokia","habanero")); Set ret = (Set) extractor.extractObject(converter,set,new Stack<String>(),false); assertEquals(ret,set); }