I am trying to save the instance of the class bellow into dynamdb but getting
DynamoDBMappingException: not supported; requires @DynamoDBTyped or @DynamoDBTypeConverted
exception.
@DynamoDBTable(tableName = "FulfillmentOrders")
public class FulfillmentOrder {
@DynamoDBHashKey
private String orderId;
@DynamoDBAttribute
@DynamoDBTyped(value = DynamoDBMapperFieldModel.DynamoDBAttributeType.M)
private Map<String, Object> body;
.......
}
It fails during map conversion, seems the problem is in Object generic type.
could someone help, where is the problem here or maybe SDK doesn't support such kind of conversion ?
Thanks!
DynamoDB won't know how to convert the object
s in the Map<,>
, you'll have to create a custom type converter. once you've done this you can annotate the prooperty with @DynamoDBTypeConverted(converter = xxx)
:
In your example:
@DynamoDBTable(tableName = "FulfillmentOrders")
public class FulfillmentOrder {
@DynamoDBHashKey
private String orderId;
@DynamoDBAttribute
@DynamoDBTypeConverted(converter = BodyTypeConverter.class)
private Map<String, Object> body;
}
static public class BodyTypeConverter implements DynamoDBTypeConverter<String, Map<String, Object>> {
@Override
public String convert(Map<String, Object> object) {
DimensionType itemDimensions = (Map<String, Object>) object;
// Convert the object to a DynamoDB json string
String json = "wibble";
return json;
}
@Override
public DimensionType unconvert(String s) {
Map<String, Object> item = new Map<String, Object>();
// Convert s to a Map<String, Object> here.
return item;
}
}
More information can be found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With