You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and large value (for example "amount"=999999999.12345678) MultipleOfValidator uses node.doubleValue() for getting node value and looses precision. Jackson DeserializationFeature flag USE_BIG_DECIMAL_FOR_FLOATS set to true.
Expected error is "amount: must be multiple of 1.0E-7"
The text was updated successfully, but these errors were encountered:
Way to fix
com.networknt.schema.MultipleOfValidator.validate
public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String at) {
debug(logger, node, rootNode, at);
if (node.isNumber()) {
double nodeValue = node.doubleValue();
if (divisor != 0) {
// convert to BigDecimal since double type is not accurate enough to do the division and multiple
BigDecimal accurateDividend = node.isBigDecimal() ? node.decimalValue() : new BigDecimal(String.valueOf(nodeValue));
BigDecimal accurateDivisor = new BigDecimal(String.valueOf(divisor));
if (accurateDividend.divideAndRemainder(accurateDivisor)[1].abs().compareTo(BigDecimal.ZERO) > 0) {
return Collections.singleton(buildValidationMessage(at, "" + divisor));
}
}
}
return Collections.emptySet();
}
@ubergrohman It makes sense to convert to BigDecimal to do the calculation. Could you please submit a PR with your fix? Github gives credit where credit is due :)
When using json schema with multipleOf restriction
and large value (for example "amount"=999999999.12345678) MultipleOfValidator uses node.doubleValue() for getting node value and looses precision. Jackson DeserializationFeature flag USE_BIG_DECIMAL_FOR_FLOATS set to true.
Expected error is "amount: must be multiple of 1.0E-7"
The text was updated successfully, but these errors were encountered: