@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") Set<byte[]> buffers = (Set<byte[]>) obj; List<ByteBuffer> attributes = new ArrayList<ByteBuffer>(buffers.size()); for (byte[] b : buffers) { attributes.add(ByteBuffer.wrap(b)); } return new AttributeValue().withBS(attributes); } }
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") Set<ByteBuffer> buffers = (Set<ByteBuffer>) obj; List<ByteBuffer> attributes = new ArrayList<ByteBuffer>(buffers.size()); for (ByteBuffer b : buffers) { attributes.add(b); } return new AttributeValue().withBS(attributes); } }
update.getValue() .withB(entry.getValue().getB()) .withBS(entry.getValue().getBS()) .withN(entry.getValue().getN()) .withNS(entry.getValue().getNS())
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") final Set<byte[]> buffers = (Set<byte[]>) obj; final List<ByteBuffer> attributes = new ArrayList<ByteBuffer>(buffers.size()); for (final byte[] b : buffers) { attributes.add(ByteBuffer.wrap(b)); } return new AttributeValue().withBS(attributes); } }
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") final Set<ByteBuffer> buffers = (Set<ByteBuffer>) obj; final List<ByteBuffer> attributes = new ArrayList<ByteBuffer>(buffers.size()); for (final ByteBuffer b : buffers) { attributes.add(b); } return new AttributeValue().withBS(attributes); } }
update.getValue() .withB(entry.getValue().getB()) .withBS(entry.getValue().getBS()) .withN(entry.getValue().getN()) .withNS(entry.getValue().getNS())
@Test public void testBinarySet() { Assert.assertNull(unconvert("getByteArraySet", "setByteArraySet", new AttributeValue().withNULL(true))); Assert.assertNull(unconvert("getByteBufferSet", "setByteBufferSet", new AttributeValue().withNULL(true))); final ByteBuffer test = ByteBuffer.wrap("test".getBytes(StringUtils.UTF8)); final Set<byte[]> result = (Set<byte[]>) unconvert( "getByteArraySet", "setByteArraySet", new AttributeValue().withBS(test.slice())); assertEquals(1, result.size()); Assert.assertTrue(Arrays.equals( "test".getBytes(StringUtils.UTF8), result.iterator().next())); Assert.assertEquals(Collections.singleton(test.slice()), unconvert("getByteBufferSet", "setByteBufferSet", new AttributeValue().withBS(test.slice()))); }
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") Set<ByteBuffer> buffers = (Set<ByteBuffer>) obj; List<ByteBuffer> attributes = new ArrayList<ByteBuffer>(buffers.size()); for (ByteBuffer b : buffers) { attributes.add(b); } return new AttributeValue().withBS(attributes); } }
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") Set<byte[]> buffers = (Set<byte[]>) obj; List<ByteBuffer> attributes = new ArrayList<ByteBuffer>(buffers.size()); for (byte[] b : buffers) { attributes.add(ByteBuffer.wrap(b)); } return new AttributeValue().withBS(attributes); } }
@Override public AttributeValue getAttributeValue(String... values) { return new AttributeValue().withBS(DynamoDBUtil.base64StringToByteBuffer(values)); }
@Override public AttributeValue getAttributeValue(String... values) { return new AttributeValue().withBS(DynamoDBUtil.base64StringToByteBuffer(values)); }
update.getValue() .withB(entry.getValue().getB()) .withBS(entry.getValue().getBS()) .withN(entry.getValue().getN()) .withNS(entry.getValue().getNS())
@Test public void testBinarySerialization() { Random rnd = new Random(); Gson gson = DynamoDBUtil.getGson(); Type type = new TypeToken<Map<String, AttributeValue>>() { }.getType(); int loop = 1000; int totalByteArrays = 50; int byteArrayLength = 1024; List<ByteBuffer> byteBuffers = new ArrayList<>(); for (int i = 0; i < totalByteArrays; i++) { byte[] bytes = new byte[byteArrayLength]; rnd.nextBytes(bytes); byteBuffers.add(ByteBuffer.wrap(bytes)); } for (int i = 0; i < loop; i++) { Map<String, AttributeValue> map = new HashMap<>(); map.put("hash", new AttributeValue().withB(byteBuffers.get(rnd.nextInt(totalByteArrays)))); map.put("range", new AttributeValue().withB(byteBuffers.get(rnd.nextInt(totalByteArrays)))); map.put("list", new AttributeValue().withBS(byteBuffers.get(rnd.nextInt(totalByteArrays)), byteBuffers.get(rnd.nextInt(totalByteArrays)))); Map<String, AttributeValue> dynamoDBItem = gson.fromJson(gson.toJson(map, type), type); compare(map, dynamoDBItem); } }
public static Map<String, AttributeValue> getRandomItem() { Map<String, AttributeValue> item = new HashMap<>(); item.put("S", new AttributeValue().withS(getRandomString())); item.put("SS", new AttributeValue().withSS(getRandomStrings())); item.put("N", new AttributeValue().withN(getRandomNumber())); item.put("L", new AttributeValue().withL(new AttributeValue().withM(aRandomMap))); item.put("NS", new AttributeValue().withNS(getRandomNumbers())); item.put("B", new AttributeValue().withB(getRandomByteBuffer())); item.put("BS", new AttributeValue().withBS(getRandomByteBuffers())); return item; }
AttributeValueUpdate txItemUpdate = new AttributeValueUpdate() .withAction(AttributeAction.ADD) .withValue(new AttributeValue().withBS(Arrays.asList(requestBytes)));