3

We are planning to use DynamoDB Stream, part of stream processing we need com.amazonaws.services.dynamodbv2.model.Record object to be serialized and deserialized. I know we can do java ObjectOutputStream and ObjectInputStream, but this does not suffice our needs.

The need is we have to manage versions in deserializer and serializer because if there is a change in Record structure or new version, we can not upgrade all the services which use deserializer to upgrade at one shot.

Is there a way to do this?

Gajendra Naidu
  • 395
  • 3
  • 16
  • The data that you get from a DynamoDB stream is in raw DynamoDB JSON, so I'm not sure I understand the question. – Jason Wadsworth Jan 31 '20 at 23:00
  • Actually, We are using KinesisStreamConsumer as part of the Stream Processing application. So the com.amazonaws.services.dynamodbv2.model.Record is the object that we get. We need to deserialize and serialize that object. – Gajendra Naidu Feb 01 '20 at 15:52
  • That object/class as a `StreamRecord`. The `StreamRecord` has a `OldImage` and `NewImage` that will be populated with the DynamoDB raw data (a string, AttributeValue map). – Jason Wadsworth Feb 02 '20 at 16:59

2 Answers2

2

I think I found a solution.

Serialize : new RecordAdapter(record).getData

Deserialize: new RecordObjectMapper().readValue(new String(bytes), Record.class)

Thank you, Jason

Gajendra Naidu
  • 395
  • 3
  • 16
1

For anyone coming back to this in 2022, the classes are here: https://javadoc.io/static/com.amazonaws/dynamodb-streams-kinesis-adapter/1.5.0/index.html?com/amazonaws/services/dynamodbv2/streamsadapter/model/RecordAdapter.html

in the dynamodb-streams-kinesis-adapter library

project is here: https://github.com/awslabs/dynamodb-streams-kinesis-adapter