I have a question about applying bean validation 2.0

I am applying bean validation 2.0 in my project.

When I apply the following part of the bean validation2.0 function, it works in java but not in kotlin.

support for validating container elements by annotating type arguments of parameterized types e.g. List<@Positive Integer> positiveNumbers. This also includes:

Below is the code I tested:

@Transactional
@ExtendWith(SpringExtension::class)
@ComponentScan
@SpringBootTest(classes = arrayOf(Application::class))
class FooTest {
@Autowired
lateinit var fooService: FooService

    @Test
    fun test() {
        var foo = Foo()
        foo.values.add(4)
        fooService.foo(foo)
    }
}

@Validated
@Service
class FooService {
    fun foo(@Valid foo: Foo) {

    }
}

**kotlin** 
class Foo {
    var values: MutableList<@Min(10) Int> = mutableListOf()
}

**java**
public class Foo {
    List<@Min(10) Integer> values = new ArrayList();
}

Why does not it work in kotlin?
Thank you.

1 Like

I ran into the same issue and described it here - spring mvc - Kotlin data class and bean validation with container element constraints - Stack Overflow

I also came up with a sample project to reproduce the case:

Any ideas on this?