AbstractDynamoDao extends AbstractDao<M,P,K,I> { protected Object toStorageValue(Object val) { if (val == null) { return null; } if (val instanceof Number || val instanceof Collection || val instanceof Map || val instanceof Boolean) { return val; } else if (val instanceof Instant) { return ((Instant) val).toEpochMilli(); } else { return val.toString(); } } AbstractDynamoDao(Class<M> modelClass, Class<P> partialClass, AmazonDynamoDB db, String tableName);  AbstractDynamoDao(Class<M> modelClass, Class<P> partialClass, AmazonDynamoDB db, String tableName, ItemMapper<M> modelMapper, ItemMapper<P> partialMapper); String getTableName(); Table getTable(); Optional<M> loadOpt(K id); Optional<P> loadOpt(K id, Iterable<String> fields); @Override Iterable<M> iterateAll(); Results<M,K> scanAll(); @Override M create(P partial, Instant createAt, I creatorId); void update(K id, Update<P> update, Instant updateAt, I updaterId); M updateAndReturn(K id, Update<P> update, Instant updateAt, I updaterId); Update<P> updateOf(P partial); Update<P> updateOf(P partial, Iterable<String> removeFields); @Override void delete(K id); abstract List<KeySchemaElement> getKeySchema(); abstract List<AttributeDefinition> getAttributeDefinitions(); List<GlobalSecondaryIndex> getGlobalSecondaryIndexes(); void initTable(); void dropTable(); void copyTable(AmazonDynamoDB sourceDb, String sourceTable); void ensureIndexes();  }
@Test public void testToStorageValue() throws Exception { Map<String,Object> myMap = ImmutableMap.of("test", 1); assertEquals(myMap, dao.toStorageValue(myMap)); }
@Test public void testToPropertyValue() throws Exception { assertNull(dao.toStorageValue(null)); assertEquals(1, dao.toStorageValue(1)); assertEquals("test", dao.toStorageValue("test")); UUID id = UUID.randomUUID(); assertEquals(id.toString(), dao.toStorageValue(id)); Instant time = Instant.now(); assertEquals(time.toEpochMilli(), dao.toStorageValue(time)); }