-
Notifications
You must be signed in to change notification settings - Fork 909
DynamoDB Enhanced Client: Provide JSON Attribute Converter Out of the Box #2162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'd also vote for such functionality coming out of the box as probably being really widely used. |
Coupling SDK with particular JSON implementation doesn't make much sense IMO as projects may use different JSON libraries (Jackson, Gson, e.t.c) to tackle that problem. Another drawback is exception handling. Users (not library) should decide what kind of exception should be thrown on JSON parsing/serializing error. You can easily implement
Then you create subclass per attribute type you want to convert
Finally, you can use it as annotation on your model:
|
A default implementation for jackson users could save devs a considerable amount of time. |
Thank you very much for this! It worked! |
Any guidance on how to make work with generic object types? For example Snapshot<?> snapshot; |
Is it possible to use or extract few properties from json? I mean I have lot of properties, but in the first queriyes I just need to two properties from from the json. Is that possible? |
Hi, |
We are encountering the same problem. Is there a solution or an alternative available for us to implement in Java2? |
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 genericAttributeConverters
internally, and I foundclass 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 theSetAttributeConverter<T>
is a good template for how this proposedJsonAttributeConverter<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.The text was updated successfully, but these errors were encountered: