@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") Set<String> set = (Set<String>) obj; List<String> strings = new ArrayList<String>(set.size()); for (String s : set) { strings.add(s); } return new AttributeValue().withSS(strings); } }
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") Set<UUID> uuids = (Set<UUID>) obj; List<String> strings = new ArrayList<String>(uuids.size()); for (UUID uuid : uuids) { strings.add(uuid.toString()); } return new AttributeValue().withSS(strings); } }
@Override public AttributeValue marshall(Object obj) { Set<?> set = (Set<?>) obj; LOG.warn("Marshaling a set of non-String objects to a DynamoDB " + "StringSet. You won't be able to read these objects back " + "out of DynamoDB unless you REALLY know what you're doing: " + "it's probably a bug. If you DO know what you're doing feel" + "free to ignore this warning, but consider using a custom " + "marshaler for this instead."); List<String> strings = new ArrayList<String>(set.size()); for (Object o : set) { strings.add(String.valueOf(o)); } return new AttributeValue().withSS(strings); } }
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") Set<Calendar> dates = (Set<Calendar>) obj; List<String> timestamps = new ArrayList<String>(dates.size()); for (Calendar date : dates) { timestamps.add(DateUtils.formatISO8601Date(date.getTime())); } return new AttributeValue().withSS(timestamps); } }
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") Set<Date> dates = (Set<Date>) obj; List<String> timestamps = new ArrayList<String>(dates.size()); for (Date date : dates) { timestamps.add(DateUtils.formatISO8601Date(date)); } return new AttributeValue().withSS(timestamps); } }
.withNS(entry.getValue().getNS()) .withS(entry.getValue().getS()) .withSS(entry.getValue().getSS()) .withM(entry.getValue().getM()) .withL(entry.getValue().getL())
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") final Set<String> set = (Set<String>) obj; final List<String> strings = new ArrayList<String>(set.size()); for (final String s : set) { strings.add(s); } return new AttributeValue().withSS(strings); } }
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") final Set<Calendar> dates = (Set<Calendar>) obj; final List<String> timestamps = new ArrayList<String>(dates.size()); for (final Calendar date : dates) { timestamps.add(DateUtils.formatISO8601Date(date.getTime())); } return new AttributeValue().withSS(timestamps); } }
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") final Set<Date> dates = (Set<Date>) obj; final List<String> timestamps = new ArrayList<String>(dates.size()); for (final Date date : dates) { timestamps.add(DateUtils.formatISO8601Date(date)); } return new AttributeValue().withSS(timestamps); } }
@Override public AttributeValue marshall(Object obj) { final Set<?> set = (Set<?>) obj; LOG.warn("Marshaling a set of non-String objects to a DynamoDB " + "StringSet. You won't be able to read these objects back " + "out of DynamoDB unless you REALLY know what you're doing: " + "it's probably a bug. If you DO know what you're doing feel" + "free to ignore this warning, but consider using a custom " + "marshaler for this instead."); final List<String> strings = new ArrayList<String>(set.size()); for (final Object o : set) { strings.add(String.valueOf(o)); } return new AttributeValue().withSS(strings); } }
.withNS(entry.getValue().getNS()) .withS(entry.getValue().getS()) .withSS(entry.getValue().getSS()); } else { updateValues.put(entry.getKey(),
@Test public void testDateSet() { assertEquals(Collections.singleton(new Date(0)), unconvert("getDateSet", "setDateSet", new AttributeValue() .withSS("1970-01-01T00:00:00.000Z"))); final Calendar c = Calendar.getInstance(); c.setTimeInMillis(0); assertEquals(Collections.singleton(c), unconvert("getCalendarSet", "setCalendarSet", new AttributeValue() .withSS("1970-01-01T00:00:00.000Z"))); }
@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 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 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 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 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 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")); } }))); }
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; }