Slide 20
Slide 20 text
data class AccountNumbersPassiveDto(
@NotNull
val accountNumberLong: Long?,
val accountNumberNullable: Long?,
@DecimalMax(value = "10")
@DecimalMin(value = "5")
val accountNumber: BigDecimal,
val accountNumberEven: Int,
val accountNumberOdd: Int,
@Positive
val accountNumberPositive: Int,
@Negative
val accountNumberNegative: Int,
val accountNumberMaxList:Int
)
Will this work?
Not really … 🤔
public final class AccountNumbersPassiveDto {
@Nullable
private final Long accountNumberLong;
@Nullable
private final Long accountNumberNullable;
@NotNull
private final BigDecimal accountNumber;
private final int accountNumberEven;
private final int accountNumberOdd;
private final int accountNumberPositive;
private final int accountNumberNegative;
private final int accountNumberMaxList;
Decompiling
the bytecode to Java
No annotation has been applied to
a field! How is this possible?
Since we do not specify where the
annotation is supposed to be
applied, it gets applied however it
is configured by default.
@Nullable is applied because
that is how the bytecode
translates back to Java when we
mark it as final with val and
nullable with.
The solution?
Use-site targets!
The problem