aws-sdk2-dynamo-json-helper
aws-sdk2-dynamo-json-helper copied to clipboard
DynamoDB only supports precision up to 38 digits
When trying to persist an BigDecimal with more then 38 digits after the "." dynamodb is throwing an error.
I also thought who is doing something like that but in our existing test code was a BigDecimal initialisation not with a string but with an double new BigDecimal(13.2)
what causes the the more the 38 digits.
I would suggest to round in that case the decimal value like this:
private static AttributeValue toAttributeValue(NumericNode numericNode) {
if (numericNode.decimalValue() != null && numericNode.decimalValue().precision() > 38) {
return AttributeValue.builder().n(numericNode.decimalValue().round(new MathContext(38, RoundingMode.CEILING)).toString()).build();
}
return AttributeValue.builder().n(numericNode.asText()).build();
}