aws-sdk-java-v2
aws-sdk-java-v2 copied to clipboard
AttributeValue is not serializable
Describe the bug
The AttributeValue class implements the Serializable interface. However, when trying to serialize it using java.io.ObjectOutputStream writeObject method I get the following error: java.io.NotSerializableException: software.amazon.awssdk.core.util.DefaultSdkAutoConstructList
The reason is that the AttributeValue.Builder the constructor sets DefaultSdkAutoConstructList (which is not serializable) to all list type properties such as "l", "ss", "ns", and "bs"
Expected behavior
AttributeValue should be serializable, and not throw an exception during serialization.
Current behavior
An exception - java.io.NotSerializableException: software.amazon.awssdk.core.util.DefaultSdkAutoConstructList is thrown when trying to serialize it using java.io.ObjectOutputStream writeObject method
Caused by: java.io.NotSerializableException: software.amazon.awssdk.core.util.DefaultSdkAutoConstructList
at java.base/java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1185)
at java.base/java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1553)
at java.base/java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1510)
at java.base/java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1433)
at java.base/java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1179)
at java.base/java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:349)
Steps to Reproduce
Simple code:
AttributeValue attributeValue = AttributeValue.builder()
.n("123")
.build();
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream)) {
objectOutputStream.writeObject(attributeValue);
} catch (IOException e) {
throw new RuntimeException(e);
}
Possible Solution
software.amazon.awssdk.core.util.DefaultSdkAutoConstructList should implement Serializable
Context
No response
AWS Java SDK version used
2.17.161
JDK version used
11.0.14.1
Operating System and version
Ubuntu 20.04.4 LTS
@nirtsruya thank you for reaching out. Your analysis is correct, AttributeValue won't be serializable due to the list structures. This was not a planned use case for AttributeValue, so I'm considering this a feature request.
This breaks other things too .. S3Object
is no longer Serializable (despite having the Serializable marker) because this class is not Serializable (SDK v2.18.32).
Any update or plan to fix this issue?
+1 Waiting for this feature, I was able to serialize before v2.