Validating strings inside a List works in Java: ``...
# spring
h
Validating strings inside a List works in Java:
Copy code
import jakarta.validation.constraints.Size;
import java.util.List;

public record UploadRequestJ(
        @Size(min = 1, message = "Must provide checksums")
        List<@Size(min = 1, message = "Checksum can't be empty") String> checksums
) {}
but doesn’t in Kotlin:
Copy code
import jakarta.validation.constraints.Size

data class UploadRequestKt(
    @get:Size(min = 1, message = "Must provide checksums")
    val checksums: List<@Size(min = 1, message = "Checksum can't be empty") String>
)
The string length isn’t checked when using the Kotlin version. Is there a workaround?
✅ 1
j
We have
Copy code
compilerOptions {
        ...
        // Emit TYPE_USE annotations (e.g. List<@Valid Foo>) into the bytecode so Bean Validation
        // can cascade into container elements. Without this Kotlin silently drops them.
        freeCompilerArgs.add("-Xemit-jvm-type-annotations")
    }
h
Thank you, this solves it!
I’m wondering why this isn’t generated by default when using start.spring.io
I made an issue and the awesome Spring team fixed it in no time: github.com/spring-io/start.spring.io/issues/2329 ☺️
💯 1