Java Code Examples for software.amazon.awssdk.services.dynamodb.model.AttributeValue#s()
The following examples show how to use
software.amazon.awssdk.services.dynamodb.model.AttributeValue#s() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OffsetDateTimeAsStringAttributeConverter.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public OffsetDateTime transformTo(AttributeValue input) { try { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } catch (RuntimeException e) { throw new IllegalArgumentException(e); } }
Example 2
Source File: DynamoUtils.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
public static String safeGetString(Map<String, AttributeValue> dynamoRecord, String key) { AttributeValue av = dynamoRecord.get(key); if (av == null) { return null; } else { return av.s(); } }
Example 3
Source File: DirectKmsMaterialsProvider.java From aws-dynamodb-encryption-java with Apache License 2.0 | 5 votes |
/** * Extracts relevant information from {@code context} and uses it to populate fields in * {@code kmsEc}. Subclass can override the default implementation to provide an alternative * encryption context in calls to KMS. Currently, the default implementation includes these fields: * <dl> * <dt>{@code HashKeyName}</dt> * <dd>{@code HashKeyValue}</dd> * <dt>{@code RangeKeyName}</dt> * <dd>{@code RangeKeyValue}</dd> * <dt>{@link #TABLE_NAME_EC_KEY}</dt> * <dd>{@code TableName}</dd> */ protected void populateKmsEcFromEc(EncryptionContext context, Map<String, String> kmsEc) { final String hashKeyName = context.getHashKeyName(); if (hashKeyName != null) { final AttributeValue hashKey = context.getAttributeValues().get(hashKeyName); if (hashKey.n() != null) { kmsEc.put(hashKeyName, hashKey.n()); } else if (hashKey.s() != null) { kmsEc.put(hashKeyName, hashKey.s()); } else if (hashKey.b() != null) { kmsEc.put(hashKeyName, Base64.encodeToString(hashKey.b().asByteArray())); } else { throw new UnsupportedOperationException("DirectKmsMaterialsProvider only supports String, Number, and Binary HashKeys"); } } final String rangeKeyName = context.getRangeKeyName(); if (rangeKeyName != null) { final AttributeValue rangeKey = context.getAttributeValues().get(rangeKeyName); if (rangeKey.n() != null) { kmsEc.put(rangeKeyName, rangeKey.n()); } else if (rangeKey.s() != null) { kmsEc.put(rangeKeyName, rangeKey.s()); } else if (rangeKey.b() != null) { kmsEc.put(rangeKeyName, Base64.encodeToString(rangeKey.b().asByteArray())); } else { throw new UnsupportedOperationException("DirectKmsMaterialsProvider only supports String, Number, and Binary RangeKeys"); } } final String tableName = context.getTableName(); if (tableName != null) { kmsEc.put(TABLE_NAME_EC_KEY, tableName); } }
Example 4
Source File: AttributeValueCoder.java From beam with Apache License 2.0 | 5 votes |
@Override public void encode(AttributeValue value, OutputStream outStream) throws IOException { if (value.s() != null) { StringUtf8Coder.of().encode(AttributeValueType.s.toString(), outStream); StringUtf8Coder.of().encode(value.s(), outStream); } else if (value.n() != null) { StringUtf8Coder.of().encode(AttributeValueType.n.toString(), outStream); StringUtf8Coder.of().encode(value.n(), outStream); } else if (value.bool() != null) { StringUtf8Coder.of().encode(AttributeValueType.bool.toString(), outStream); BooleanCoder.of().encode(value.bool(), outStream); } else if (value.b() != null) { StringUtf8Coder.of().encode(AttributeValueType.b.toString(), outStream); ByteArrayCoder.of().encode(value.b().asByteArray(), outStream); } else if (value.ss() != null && value.ss().size() > 0) { StringUtf8Coder.of().encode(AttributeValueType.ss.toString(), outStream); LIST_STRING_CODER.encode(value.ss(), outStream); } else if (value.ns() != null && value.ns().size() > 0) { StringUtf8Coder.of().encode(AttributeValueType.ns.toString(), outStream); LIST_STRING_CODER.encode(value.ns(), outStream); } else if (value.bs() != null && value.bs().size() > 0) { StringUtf8Coder.of().encode(AttributeValueType.bs.toString(), outStream); LIST_BYTE_CODER.encode(convertToListByteArray(value.bs()), outStream); } else if (value.l() != null && value.l().size() > 0) { StringUtf8Coder.of().encode(AttributeValueType.l.toString(), outStream); LIST_ATTRIBUTE_CODER.encode(value.l(), outStream); } else if (value.m() != null && value.m().size() > 0) { StringUtf8Coder.of().encode(AttributeValueType.m.toString(), outStream); MAP_ATTRIBUTE_CODER.encode(value.m(), outStream); } else if (value.nul() != null) { StringUtf8Coder.of().encode(AttributeValueType.nul.toString(), outStream); BooleanCoder.of().encode(value.nul(), outStream); } else { throw new CoderException("Unknown Type"); } }
Example 5
Source File: LocalDateAttributeConverter.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public LocalDate transformTo(AttributeValue input) { try { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } catch (RuntimeException e) { throw new IllegalArgumentException(e); } }
Example 6
Source File: ZonedDateTimeAsStringAttributeConverter.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public ZonedDateTime transformTo(AttributeValue input) { try { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } catch (RuntimeException e) { throw new IllegalArgumentException(e); } }
Example 7
Source File: LocalTimeAttributeConverter.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public LocalTime transformTo(AttributeValue input) { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); }
Example 8
Source File: EnhancedAttributeValue.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Create an {@link EnhancedAttributeValue} from a generated {@link AttributeValue}. * * <p> * This call will fail with a {@link RuntimeException} if the provided value is null ({@link AttributeValue#nul()} is okay). */ public static EnhancedAttributeValue fromAttributeValue(AttributeValue attributeValue) { Validate.notNull(attributeValue, "Generated attribute value must not contain null values. " + "Use AttributeValue#nul() instead."); if (attributeValue.s() != null) { return EnhancedAttributeValue.fromString(attributeValue.s()); } if (attributeValue.n() != null) { return EnhancedAttributeValue.fromNumber(attributeValue.n()); } if (attributeValue.bool() != null) { return EnhancedAttributeValue.fromBoolean(attributeValue.bool()); } if (Boolean.TRUE.equals(attributeValue.nul())) { return EnhancedAttributeValue.nullValue(); } if (attributeValue.b() != null) { return EnhancedAttributeValue.fromBytes(attributeValue.b()); } if (attributeValue.hasM()) { return EnhancedAttributeValue.fromMap(attributeValue.m()); } if (attributeValue.hasL()) { return EnhancedAttributeValue.fromListOfAttributeValues(attributeValue.l()); } if (attributeValue.hasBs()) { return EnhancedAttributeValue.fromSetOfBytes(attributeValue.bs()); } if (attributeValue.hasSs()) { return EnhancedAttributeValue.fromSetOfStrings(attributeValue.ss()); } if (attributeValue.hasNs()) { return EnhancedAttributeValue.fromSetOfNumbers(attributeValue.ns()); } throw new IllegalStateException("Unable to convert attribute value: " + attributeValue); }
Example 9
Source File: CharacterAttributeConverter.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public Character transformTo(AttributeValue input) { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); }
Example 10
Source File: InstantAsStringAttributeConverter.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public Instant transformTo(AttributeValue input) { try { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } catch (RuntimeException e) { throw new IllegalArgumentException(e); } }
Example 11
Source File: MonthDayAttributeConverter.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public MonthDay transformTo(AttributeValue input) { try { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } catch (RuntimeException e) { throw new IllegalArgumentException(e); } }
Example 12
Source File: LocalDateTimeAttributeConverter.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public LocalDateTime transformTo(AttributeValue input) { try { if (input.s() != null) { return EnhancedAttributeValue.fromString(input.s()).convert(VISITOR); } return EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } catch (RuntimeException e) { throw new IllegalArgumentException(e); } }
Example 13
Source File: SingleConverterProvidersBean.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public String transformTo(AttributeValue input) { return input.s(); }
Example 14
Source File: EmptyConverterProvidersInvalidBean.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public String transformTo(AttributeValue input) { return input.s(); }
Example 15
Source File: AttributeConverterBean.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public AttributeItem transformTo(AttributeValue input) { return new AttributeItem(input.s()); }
Example 16
Source File: MultipleConverterProvidersBean.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public String transformTo(AttributeValue input) { return input.s(); }
Example 17
Source File: EmptyConverterProvidersValidBean.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Override public String transformTo(AttributeValue input) { return input.s(); }
Example 18
Source File: AttributeValueMarshaller.java From aws-dynamodb-encryption-java with Apache License 2.0 | 4 votes |
private static AttributeValue unmarshall(final DataInputStream in) throws IOException { char type = in.readChar(); AttributeValue.Builder result = AttributeValue.builder(); switch (type) { case '\0': result.nul(Boolean.TRUE); break; case 'b': result.b(SdkBytes.fromByteBuffer(readBytes(in))); break; case 'B': result.bs(readBytesList(in).stream().map(SdkBytes::fromByteBuffer).collect(Collectors.toList())); break; case 'n': result.n(readString(in)); break; case 'N': result.ns(readStringList(in)); break; case 's': result.s(readString(in)); break; case 'S': result.ss(readStringList(in)); break; case '?': final byte boolValue = in.readByte(); if (boolValue == TRUE_FLAG) { result.bool(Boolean.TRUE); } else if (boolValue == FALSE_FLAG) { result.bool(Boolean.FALSE); } else { throw new IllegalArgumentException("Improperly formatted data"); } break; case 'L': final int lCount = in.readInt(); final List<AttributeValue> l = new ArrayList<>(lCount); for (int lIdx = 0; lIdx < lCount; lIdx++) { l.add(unmarshall(in)); } result.l(l); break; case 'M': final int mCount = in.readInt(); final Map<String, AttributeValue> m = new HashMap<>(); for (int mIdx = 0; mIdx < mCount; mIdx++) { final AttributeValue key = unmarshall(in); if (key.s() == null) { throw new IllegalArgumentException("Improperly formatted data"); } AttributeValue value = unmarshall(in); m.put(key.s(), value); } result.m(m); break; default: throw new IllegalArgumentException("Unsupported data encoding"); } return result.build(); }