Skip to content

DynamoDB Enhanced Client: Provide JSON Attribute Converter Out of the Box #2162

@helloworldless

Description

@helloworldless

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<T> implements AttributeConverter<T>, but it's proving to be a challenge! I wondered how the SDK v2 was handling generic AttributeConverters internally, and I found class SetAttributeConverter<T extends Collection<?>> implements AttributeConverter<T> (link) which, to be honest, I'm still trying to wrap my head around 😄 . That being said, if you think the SetAttributeConverter<T> is a good template for how this proposed JsonAttributeConverter<T> 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dynamodb-enhancedfeature-requestA feature should be added or improved.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions