in dynamodb-api/src/main/java/com/awssamples/iot/dynamodb/api/SharedHelper.java [52:87]
public static AttributeValue toDynamoDbAttributeValue(Object object) {
// NOTE: This code was borrowed from Amazon Web Services DynamoDB Mapper v1
if (object instanceof AttributeValue) {
return (AttributeValue) object;
}
if (object instanceof String) {
return AttributeValue.builder().s((String) object).build();
}
if (object instanceof Number) {
return AttributeValue.builder().n(String.valueOf((Number) object)).build();
}
if (object instanceof byte[]) {
return AttributeValue.builder().b(SdkBytes.fromByteArray((byte[]) object)).build();
}
if (object instanceof ByteBuffer) {
return AttributeValue.builder().b(SdkBytes.fromByteBuffer((ByteBuffer) object)).build();
}
if (object instanceof Boolean) {
return AttributeValue.builder().bool((Boolean) object).build();
}
if (object instanceof List) {
List<AttributeValue> attributeValues = ((List<?>) object).stream()
.map(SharedHelper::toDynamoDbAttributeValue)
.collect(toList());
return AttributeValue.builder().l(attributeValues).build();
}
if (object instanceof Map) {
Map<String, AttributeValue> attributeValues =
((Map<String, ?>) object).entrySet()
.stream()
.map(e -> new AbstractMap.SimpleImmutableEntry<>(e.getKey(), toDynamoDbAttributeValue(e.getValue())))
.collect(toMap());
return AttributeValue.builder().m(attributeValues).build();
}
throw new IllegalArgumentException("Unsupported type: " + object.getClass());
}