software.amazon.awssdk.services.sns.model.MessageAttributeValue Maven / Gradle / Ivy
Show all versions of sns Show documentation
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.sns.model;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* The user-specified message attribute value. For string data types, the value attribute has the same restrictions on
* the content as the message body. For more information, see Publish.
*
*
* Name, type, and value must not be empty or null. In addition, the message body should not be empty or null. All parts
* of the message attribute, including name, type, and value, are included in the message size restriction, which is
* currently 256 KB (262,144 bytes). For more information, see Amazon SNS message attributes and Publishing to a mobile phone in the
* Amazon SNS Developer Guide.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class MessageAttributeValue implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField DATA_TYPE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("DataType").getter(getter(MessageAttributeValue::dataType)).setter(setter(Builder::dataType))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("DataType").build()).build();
private static final SdkField STRING_VALUE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("StringValue").getter(getter(MessageAttributeValue::stringValue)).setter(setter(Builder::stringValue))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("StringValue").build()).build();
private static final SdkField BINARY_VALUE_FIELD = SdkField. builder(MarshallingType.SDK_BYTES)
.memberName("BinaryValue").getter(getter(MessageAttributeValue::binaryValue)).setter(setter(Builder::binaryValue))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("BinaryValue").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(DATA_TYPE_FIELD,
STRING_VALUE_FIELD, BINARY_VALUE_FIELD));
private static final Map> SDK_NAME_TO_FIELD = memberNameToFieldInitializer();
private static final long serialVersionUID = 1L;
private final String dataType;
private final String stringValue;
private final SdkBytes binaryValue;
private MessageAttributeValue(BuilderImpl builder) {
this.dataType = builder.dataType;
this.stringValue = builder.stringValue;
this.binaryValue = builder.binaryValue;
}
/**
*
* Amazon SNS supports the following logical data types: String, String.Array, Number, and Binary. For more
* information, see Message
* Attribute Data Types.
*
*
* @return Amazon SNS supports the following logical data types: String, String.Array, Number, and Binary. For more
* information, see Message Attribute Data Types.
*/
public final String dataType() {
return dataType;
}
/**
*
* Strings are Unicode with UTF8 binary encoding. For a list of code values, see ASCII Printable Characters.
*
*
* @return Strings are Unicode with UTF8 binary encoding. For a list of code values, see ASCII Printable Characters.
*/
public final String stringValue() {
return stringValue;
}
/**
*
* Binary type attributes can store any binary data, for example, compressed data, encrypted data, or images.
*
*
* @return Binary type attributes can store any binary data, for example, compressed data, encrypted data, or
* images.
*/
public final SdkBytes binaryValue() {
return binaryValue;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(dataType());
hashCode = 31 * hashCode + Objects.hashCode(stringValue());
hashCode = 31 * hashCode + Objects.hashCode(binaryValue());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof MessageAttributeValue)) {
return false;
}
MessageAttributeValue other = (MessageAttributeValue) obj;
return Objects.equals(dataType(), other.dataType()) && Objects.equals(stringValue(), other.stringValue())
&& Objects.equals(binaryValue(), other.binaryValue());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("MessageAttributeValue").add("DataType", dataType()).add("StringValue", stringValue())
.add("BinaryValue", binaryValue()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "DataType":
return Optional.ofNullable(clazz.cast(dataType()));
case "StringValue":
return Optional.ofNullable(clazz.cast(stringValue()));
case "BinaryValue":
return Optional.ofNullable(clazz.cast(binaryValue()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
@Override
public final Map> sdkFieldNameToField() {
return SDK_NAME_TO_FIELD;
}
private static Map> memberNameToFieldInitializer() {
Map> map = new HashMap<>();
map.put("DataType", DATA_TYPE_FIELD);
map.put("StringValue", STRING_VALUE_FIELD);
map.put("BinaryValue", BINARY_VALUE_FIELD);
return Collections.unmodifiableMap(map);
}
private static Function