Smajl
Smajl

Reputation: 7995

Do DynamoDB POJOs need to implement Serialized?

I am saving a lot of data into Amazon DynamoDB. I am using the AmazonDynamoDBClient (and sometimes DynamoDBMapper) to perform these tasks.

This is an example illustrating the process:

@Data
@DynamoDBTable(tableName = "Results")
public class Result extends DynamoEntity {

  @DynamoDBHashKey
  private String hashKey;

  @DynamoDBAttribute
  private String period;
  @DynamoDBAttribute
  private String customerId;
  @DynamoDBAttribute
  private double actualCost;
  @DynamoDBAttribute
  private double estimatedCost;

  @DynamoDBHashKey
  public String getHashKey() {
    if (hashKey == null) {
      hashKey = period + "-" + customerId;
    }
    return hashKey;
  }

}

And saving the records:

private static final AmazonDynamoDB amazonDynamoDB = new AmazonDynamoDBClient();
private static final DynamoDBMapper mapper = new DynamoDBMapper(amazonDynamoDB);

mapper.save(record);

Everything works fine, but I am just wondering whether I should implement Serializable to all the POJOs that are being saved into DB (and they are, of course, sent over the network). Is it a good practice or should I avoid it?

Upvotes: 2

Views: 1601

Answers (1)

Swapnil
Swapnil

Reputation: 8318

I think DynamoDbMapper works with primary data types like string, int, date etc out of the box. For serialization of complex types, you need to have your own custom marshallers that implement DynamoDBMarshaller and use them on your type. If you want to use json, with the built-in JsonMarshaller, it should utilize jackson, which doesn't depend on Serializable at all.

With the type you mentioned above, I don't think you need it.

Upvotes: 2

Related Questions