ItemMapper { public Item fromByteBuffer(ByteBuffer byteBuffer) { try { JsonNode node = objectMapper.readTree(byteBuffer.array()); ZonedDateTime dateTime = ZonedDateTime.parse(node.get(PERIOD_TABLE_RANGE_KEY).asText(), AWS_DATE_TIME); PrimaryKey key = key(node); Item item = new Item().withPrimaryKey(key); Iterator<Map.Entry<String, JsonNode>> iterator = node.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); if (!entry.getKey().equals(CAMPAIGN_TABLE_HASH_KEY) && !entry.getKey().equals(PERIOD_TABLE_RANGE_KEY)) { if (entry.getValue().isBoolean()) { item = item.withBoolean(entry.getKey(), entry.getValue().asBoolean()); } else if (entry.getValue().isInt()) { item = item.withInt(entry.getKey(), entry.getValue().asInt()); } else if (entry.getValue().isLong()) { item = item.withLong(entry.getKey(), entry.getValue().asLong()); } else if (entry.getValue().isDouble()) { item = item.withDouble(entry.getKey(), entry.getValue().asDouble()); } else if (entry.getValue().isFloat()) { item = item.withFloat(entry.getKey(), entry.getValue().floatValue()); } else if (entry.getValue().isTextual()) { item = item.withString(entry.getKey(), entry.getValue().asText()); } } } return item; } catch (IOException e) { throw new RuntimeException(e); } }  PrimaryKey key(ByteBuffer byteBuffer); PrimaryKey key(JsonNode node); PrimaryKey primaryKey(Item item); Map<PrimaryKey, Item> mergeItems(List<ByteBuffer> list); List<Item> mergeItems(Collection<Item> created, Collection<Item> read); Item mergeItem(PrimaryKey primaryKey, Item newItem, Item oldItem); Object mergeValue(Object newObject, Object oldValue); Item fromByteBuffer(ByteBuffer byteBuffer); static final String CAMPAIGN_TABLE_HASH_KEY; static final String PERIOD_TABLE_RANGE_KEY; }
@Test public void testMapper() throws Exception { for (Aggregation aggregation : aggregations) { Item item = itemMapper.fromByteBuffer(serialize(aggregation)); assertEquals((long) aggregation.getCampaignItemId(), item.getLong("campaign_item_id")); assertEquals((long) aggregation.getClicks(), item.getLong("clicks")); assertEquals((long) aggregation.getImps(), item.getLong("imps")); assertEquals((long) aggregation.getBids(), item.getLong("bids")); } }