DynamoDB Enhanced Client: Provide JSON Attribute Converter Out of the Box
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 51
Description
It would be nice if the DynamoDB Enhanced Client provided a JSON `AttributeConverter`, something like the SDK v1's `@DynamoDBTypeConvertedJson`. This seems like such a common use case that it would make sense for the SDK to provide it rather than every consumer of the SDK who needs it having to implement it themselves.
I did take a look at implementing it, e.g. `class JsonAttributeConverter implements AttributeConverter`, but it's proving to be a challenge! I wondered how the SDK v2 was handling generic `AttributeConverters` internally, and I found `class SetAttributeConverter> implements AttributeConverter` ([link](https://github.com/aws/aws-sdk-java-v2/blob/master/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/attribute/SetAttributeConverter.java)) which, to be honest, I'm still trying to wrap my head around 😄 . That being said, if you think the `SetAttributeConverter` is a good template for how this proposed `JsonAttributeConverter` would work, and you think this would be good for a first time contribution, I'd be happy to take a shot at it myself!
I suppose one major drawback to providing this out of the box is that I don't see a way for a consumer of the SDK to customize the `ObjectMapper`. Everywhere in the SDK, I just see this is a static field: `private static final ObjectMapper MAPPER = new ObjectMapper();`.
For now, as a workaround, I'm just using a non-parameterized, single-use `AttributeConverter` e.g. `class MyCustomEntityJsonAttributeConverter implements AttributeConverter`, the downside being that I need to create one for each custom entity that I want to be JSON converted.
Contributor guide
Assessment
This issue has not been assessed yet.