ObjectToJsonConverter { public Object extractObject(Object pValue, Stack<String> pPathParts, boolean pJsonify) throws AttributeNotFoundException { ObjectSerializationContext stackContext = stackContextLocal.get(); String limitReached = checkForLimits(pValue, stackContext); Stack<String> pathStack = pPathParts != null ? pPathParts : new Stack<String>(); if (limitReached != null) { return limitReached; } try { stackContext.push(pValue); if (pValue == null) { return pathStack.isEmpty() ? null : stackContext.getValueFaultHandler().handleException( new AttributeNotFoundException("Cannot apply a path to an null value")); } if (pValue.getClass().isArray()) { return arrayExtractor.extractObject(this,pValue,pathStack,pJsonify); } return callHandler(pValue, pathStack, pJsonify); } finally { stackContext.pop(); } } ObjectToJsonConverter(StringToObjectConverter pStringToObjectConverter,
                                 Extractor... pSimplifyHandlers); Object convertToJson(Object pValue, List<String> pPathParts, JsonConvertOptions pOptions); Object setInnerValue(Object pOuterObject, Object pNewValue, List<String> pPathParts); Object extractObject(Object pValue, Stack<String> pPathParts, boolean pJsonify); ValueFaultHandler getValueFaultHandler();  }
@Test public void basics() throws AttributeNotFoundException { Map result = (Map) converter.extractObject(new SelfRefBean1(), new Stack<String>(), true); assertNotNull("Bean2 is set",result.get("bean2")); assertNotNull("Binary attribute is set",result.get("strong")); }
@Test public void checkDeadLockDetection() throws AttributeNotFoundException { Map result = (Map) converter.extractObject(new SelfRefBean1(), new Stack<String>(), true); assertNotNull("Bean 2 is set",result.get("bean2")); assertNotNull("Bean2:Bean1 is set",((Map)result.get("bean2")).get("bean1")); assertEquals("Reference breackage",((Map)result.get("bean2")).get("bean1").getClass(),String.class); assertTrue("Bean 3 should be resolved",result.get("bean3") instanceof Map); }
@Test public void maxDepth() throws AttributeNotFoundException, NoSuchFieldException, IllegalAccessException { setOptionsViaReflection("maxDepth",2); Map result = (Map) converter.extractObject(new SelfRefBean1(), new Stack<String>(), true); String c = (String) ((Map) result.get("bean2")).get("bean1"); assertTrue("Recurence detected",c.contains("bean1: toString")); }
@Test public void maxObjects() throws NoSuchFieldException, IllegalAccessException, AttributeNotFoundException { setOptionsViaReflection("maxObjects",1); Map<String,Object> result = (Map) converter.extractObject(new InnerValueTestBean("foo", "bar", "baz"), new Stack<String>(), true); boolean found = false; for (Object val : result.values()) { if (val instanceof String) { found = ((String) val).matches("^\\[.*(limit).*\\]$"); } } assertTrue(found); }
@Test public void customSimplifier() throws AttributeNotFoundException { Date date = new Date(); Map result = (Map) converter.extractObject(date, new Stack<String>(), true); assertEquals(date.getTime(),result.get("millis")); }
@Test public void fileSimplifier() throws AttributeNotFoundException { Map result = (Map) converter.extractObject(new File("/tmp"), new Stack<String>(), true); assertNull(result.get("parent")); }
@Test public void customNegativeSimpifier() throws MalformedObjectNameException, AttributeNotFoundException { ObjectName name = new ObjectName("java.lang:type=Memory"); Map result = (Map) converter.extractObject(name, new Stack<String>(), true); assertEquals("type=Memory",result.get("canonicalKeyPropertyListString")); }