Closed abramsz closed 10 months ago
Interestingly, the javadoc says this:
Note that double and float are not supported due to rounding errors (some providers might provide some approximative support).
So I guess this is why this applies only to integers. I guess we can add the annotation anyway. If it is not supported by some validators, I assume they will just ignore it.
I have found it here. From MinimumMaximumRule.java, it is prefer to use type BigDecimal instead of Double and Float.Let's close it.
private boolean isApplicableType(JFieldVar field) {
try {
Class<?> fieldClass = Class.forName(field.type().boxify().fullName());
// Support Strings and most number types except Double and Float, per docs on DecimalMax/Min annotations
return String.class.isAssignableFrom(fieldClass) ||
(Number.class.isAssignableFrom(fieldClass) &&
!Float.class.isAssignableFrom(fieldClass) && !Double.class.isAssignableFrom(fieldClass));
} catch (ClassNotFoundException ignore) {
return false;
}
}
I try to validate the conversion from json schema to java code in https://www.jsonschema2pojo.org/. Only type of integer in schema can be used to geneate @DecimalMin("10"), for type of number, nothing has been generated.
With the following settings and json schema.
The following java code has been generated.
Thanks in advance.