DateExtractor implements Extractor { public Object extractObject(ObjectToJsonConverter pConverter, Object pValue, Stack<String> pPathParts, boolean jsonify) throws AttributeNotFoundException { if (!jsonify) { return pValue; } Date date = (Date) pValue; String pathPart = pPathParts.isEmpty() ? null : pPathParts.pop(); if (pathPart != null) { if (!"time".equals(pathPart)) { return pConverter.getValueFaultHandler().handleException( new AttributeNotFoundException("A date accepts only a single inner path element " + "of value 'time' (and not '" + pathPart + "')")); } return date.getTime(); } else { return DateUtil.toISO8601(date); } }  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 directExtract() throws AttributeNotFoundException { Date date = new Date(); Stack stack = new Stack(); Object result = extractor.extractObject(null,date,stack,false); assertEquals(result,date); stack.add("time"); result = extractor.extractObject(null,date,stack,false); assertEquals(result,date); }
@Test public void simpleJsonExtract() throws AttributeNotFoundException { Date date = new Date(); Stack stack = new Stack(); Object result = extractor.extractObject(null,date,stack,true); assertEquals(result, DateUtil.toISO8601(date)); stack.add("time"); result = extractor.extractObject(null,date,stack,true); assertEquals(result,date.getTime()); }
@Test(enabled = true, expectedExceptions = AttributeNotFoundException.class) public void simpleJsonExtractWithWrongPath() throws AttributeNotFoundException { Date date = new Date(); Stack stack = new Stack(); stack.add("blablub"); extractor.extractObject(converter, date, stack, true); }