public final AttributeValue convert(T o) { return o == null ? new AttributeValue().withNULL(true) : super.convert(o); } };
@Override public AttributeValue marshall(Object obj) { if (memberMarshaller == null) { throw new IllegalStateException( "No member marshaller configured!"); } @SuppressWarnings("unchecked") Map<String, ?> map = (Map<String, ?>) obj; Map<String, AttributeValue> values = new HashMap<String, AttributeValue>(); for (Map.Entry<String, ?> entry : map.entrySet()) { AttributeValue value; if (entry.getValue() == null) { value = new AttributeValue().withNULL(true); } else { value = memberMarshaller.marshall(entry.getValue()); } values.put(entry.getKey(), value); } AttributeValue result = new AttributeValue(); result.setM(values); return result; }
@Override public AttributeValue marshall(Object obj) { if (memberMarshaller == null) { throw new IllegalStateException( "No member marshaller configured!"); } Collection<?> objects = (Collection<?>) obj; List<AttributeValue> values = new ArrayList<AttributeValue>(objects.size()); for (Object o : objects) { AttributeValue value; if (o == null) { value = new AttributeValue().withNULL(true); } else { value = memberMarshaller.marshall(o); } values.add(value); } AttributeValue result = new AttributeValue(); result.setL(values); return result; }
.withM(entry.getValue().getM()) .withL(entry.getValue().getL()) .withNULL(entry.getValue().getNULL()) .withBOOL(entry.getValue().getBOOL()); } else {
AttributeValue result = new AttributeValue(); if (value == null) { return result.withNULL(Boolean.TRUE); } else if (value instanceof Boolean) { return result.withBOOL((Boolean)value);
protected static Map<String, AttributeValue> convertToAttributeValues( Map<String, DynamoDBEntry> valueMap, Table table) { final Map<String, AttributeValue> convertedValues = new HashMap<String, AttributeValue>(); if (valueMap != null) { for (final Entry<String, DynamoDBEntry> kvp : valueMap.entrySet()) { final String attributeName = kvp.getKey(); final DynamoDBEntry entry = kvp.getValue(); if (entry == null) { convertedValues.put(attributeName, new AttributeValue().withNULL(true)); } else { convertedValues.put(attributeName, entry.convertToAttributeValue()); } } } return convertedValues; }
@Override public AttributeValue marshall(Object obj) { if (memberMarshaller == null) { throw new IllegalStateException( "No member marshaller configured!"); } @SuppressWarnings("unchecked") final Map<String, ?> map = (Map<String, ?>) obj; final Map<String, AttributeValue> values = new HashMap<String, AttributeValue>(); for (final Map.Entry<String, ?> entry : map.entrySet()) { AttributeValue value; if (entry.getValue() == null) { value = new AttributeValue().withNULL(true); } else { value = memberMarshaller.marshall(entry.getValue()); } values.put(entry.getKey(), value); } final AttributeValue result = new AttributeValue(); result.setM(values); return result; }
@Override public AttributeValue marshall(Object obj) { if (memberMarshaller == null) { throw new IllegalStateException( "No member marshaller configured!"); } final List<?> objects = (List<?>) obj; final List<AttributeValue> values = new ArrayList<AttributeValue>(objects.size()); for (final Object o : objects) { AttributeValue value; if (o == null) { value = new AttributeValue().withNULL(true); } else { value = memberMarshaller.marshall(o); } values.add(value); } final AttributeValue result = new AttributeValue(); result.setL(values); return result; }
@Test public void testSetList() { assertEquals( Arrays.asList(new AttributeValue().withSS("a")), convert("getSetList", Arrays.asList( Collections.<String> singleton("a"))).getL()); final List<Set<String>> list = new ArrayList<Set<String>>(); list.add(null); assertEquals( Arrays.asList(new AttributeValue().withNULL(true)), convert("getSetList", list).getL()); }
@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()))); }
@Test public void testList() { assertEquals(Arrays.asList( new AttributeValue("a"), new AttributeValue("b"), new AttributeValue("c")), convert("getList", Arrays.asList("a", "b", "c")).getL()); assertEquals(Arrays.asList(new AttributeValue().withNULL(true)), convert("getList", Collections.<String> singletonList(null)).getL()); }
@Test public void testList() { assertEquals(Arrays.asList( new AttributeValue("a"), new AttributeValue("b"), new AttributeValue("c")), convert("getList", Arrays.asList("a", "b", "c")).getL()); assertEquals(Arrays.asList(new AttributeValue().withNULL(true)), convert("getList", Collections.<String> singletonList(null)).getL()); }
@Test public void testSetList() { Assert.assertNull(unconvert("getSetList", "setSetList", new AttributeValue().withNULL(true))); assertEquals(Arrays.asList(new Set[] { null }), unconvert("getSetList", "setSetList", new AttributeValue().withL( new AttributeValue().withNULL(true)))); assertEquals(Arrays.asList(Collections.singleton("a")), unconvert("getSetList", "setSetList", new AttributeValue().withL( new AttributeValue().withSS("a")))); }
@Test public void testList() { Assert.assertNull(unconvert("getList", "setList", new AttributeValue().withNULL(true))); assertEquals(Arrays.asList("a", "b", "c"), unconvert("getList", "setList", new AttributeValue().withL( new AttributeValue("a"), new AttributeValue("b"), new AttributeValue("c")))); assertEquals(Arrays.asList("a", null), unconvert("getList", "setList", new AttributeValue().withL( new AttributeValue("a"), new AttributeValue().withNULL(true)))); }
@Test public void testSetMap() { Assert.assertNull(unconvert("getSetMap", "setSetMap", new AttributeValue().withNULL(true))); assertEquals(new HashMap<String, Set<String>>() { { put("a", null); put("b", new TreeSet<String>(Arrays.asList("a", "b"))); } }, unconvert("getSetMap", "setSetMap", new AttributeValue().withM( new HashMap<String, AttributeValue>() { { put("a", new AttributeValue().withNULL(true)); put("b", new AttributeValue().withSS("a", "b")); } }))); }
@Test public void testSetMap() { assertEquals(new HashMap<String, AttributeValue>() { { put("a", new AttributeValue().withSS("a", "b")); } }, convert("getSetMap", new HashMap<String, Set<String>>() { { put("a", new TreeSet<String>(Arrays.asList("a", "b"))); } }).getM()); assertEquals(new HashMap<String, AttributeValue>() { { put("a", new AttributeValue().withSS("a")); put("b", new AttributeValue().withNULL(true)); } }, convert("getSetMap", new HashMap<String, Set<String>>() { { put("a", new TreeSet<String>(Arrays.asList("a"))); put("b", null); } }).getM()); }
@Test public void testStringSet() { Assert.assertNull(unconvert("getStringSet", "setStringSet", new AttributeValue().withNULL(true))); assertEquals(new HashSet<String>() { { add("a"); add("b"); } }, unconvert("getStringSet", "setStringSet", new AttributeValue().withSS("a", "b"))); }
@Test public void testMap() { assertEquals(new HashMap<String, AttributeValue>() { { put("a", new AttributeValue("b")); put("c", new AttributeValue("d")); put("e", new AttributeValue("f")); } }, convert("getMap", new HashMap<String, String>() { { put("a", "b"); put("c", "d"); put("e", "f"); } }).getM()); assertEquals(Collections.singletonMap("a", new AttributeValue().withNULL(true)), convert("getMap", Collections.<String, String> singletonMap("a", null)).getM()); }
@Test public void testMap() { assertEquals(new HashMap<String, AttributeValue>() { { put("a", new AttributeValue("b")); put("c", new AttributeValue("d")); put("e", new AttributeValue("f")); } }, convert("getMap", new HashMap<String, String>() { { put("a", "b"); put("c", "d"); put("e", "f"); } }).getM()); assertEquals(Collections.singletonMap("a", new AttributeValue().withNULL(true)), convert("getMap", Collections.<String, String> singletonMap("a", null)).getM()); }
@Test public void testObject() { Assert.assertNull(unconvert("getObject", "setObject", new AttributeValue().withNULL(true))); assertEquals(new SubClass(), unconvert("getObject", "setObject", new AttributeValue().withM(new HashMap<String, AttributeValue>() { { put("name", new AttributeValue("name")); put("value", new AttributeValue().withN("123")); } }))); assertEquals(new SubClass(), unconvert("getObject", "setObject", new AttributeValue().withM(new HashMap<String, AttributeValue>() { { put("name", new AttributeValue("name")); put("value", new AttributeValue().withN("123")); put("null", new AttributeValue().withNULL(true)); } }))); }