DateExtractor implements Extractor { public Object setObjectValue(StringToObjectConverter pConverter, Object pInner, String pAttribute, Object pValue) throws IllegalAccessException, InvocationTargetException { Date date = (Date) pInner; if ("time".equals(pAttribute)) { long time; long oldValue = date.getTime(); if (pValue instanceof String) { time = Long.parseLong((String) pValue); } else { time = (Long) pValue; } date.setTime(time); return oldValue; } else if ("iso8601".equals(pAttribute)) { Date newDate = DateUtil.fromISO8601(pValue.toString()); String oldValue = DateUtil.toISO8601(date); date.setTime(newDate.getTime()); return oldValue; } throw new UnsupportedOperationException("Setting of date values is not yet supported directly. " + "Use a path/attribute 'time' to set the epoch seconds on a 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 timeSet() throws InvocationTargetException, IllegalAccessException { Date date = new Date(); long currentTime = date.getTime(); Object oldVal = extractor.setObjectValue(null,date,"time",0L); assertEquals(oldVal,currentTime); assertEquals(date.getTime(),0L); oldVal = extractor.setObjectValue(null,date,"time","1000"); assertEquals(oldVal,0L); assertEquals(date.getTime(),1000L); }
@Test public void iso8601Set() throws InvocationTargetException, IllegalAccessException { Date date = new Date(); String current = DateUtil.toISO8601(date); Object oldVal = extractor.setObjectValue(null,date,"iso8601",DateUtil.toISO8601(new Date(0))); assertEquals(oldVal,current); assertEquals(date.getTime(),0L); }
@Test(expectedExceptions = { UnsupportedOperationException.class }) public void invalidSet() throws InvocationTargetException, IllegalAccessException { Object oldVal = extractor.setObjectValue(null,new Date(),"blubbla",0L); }