aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

AttributeValue is not serializable

Open nirtsruya opened this issue 2 years ago • 5 comments

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 avatar Apr 02 '22 17:04 nirtsruya

@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.

debora-ito avatar Apr 06 '22 18:04 debora-ito

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).

maiken2051 avatar Dec 07 '22 18:12 maiken2051

Any update or plan to fix this issue?

kevnzhao avatar Feb 22 '23 07:02 kevnzhao

+1 Waiting for this feature, I was able to serialize before v2.

alecuba16 avatar Aug 14 '23 09:08 alecuba16