5

I'm struggling with validation in String Boot.

I have the following class in Kotlin:

class ListBlock(
    @field:Size(max = 5)
    val style: String,

    @field:Valid
    @field:Size(max = 10)
    val items: List<@Size(max = 50) String>
)

@field:Size(max = 5) on style works fine by having size > 5

@field:Size(max = 10) on items works fine by having more than 10 strings in the list

I don't get any errors if one of the strings in the list has a size larger than 50 characters.

7
  • Already tried the @Length annotation? Commented Nov 5, 2020 at 15:11
  • No, but I tried now. Works the same way as @Size Commented Nov 5, 2020 at 15:28
  • What version of hibernate-validator do you use? Commented Nov 5, 2020 at 15:44
  • I'm using spring.boot.starter.validation:2.3.4.RELEASE org.hibernate.validator:6.1.5.Final Commented Nov 6, 2020 at 15:58
  • Already tried this?: stackoverflow.com/a/49941439/7919904 Commented Nov 9, 2020 at 12:46

1 Answer 1

6

You have to compile to Java 1.8 or higher (for bytecode to support type annotations), and use Kotlin 1.3.70 or higher with the option -Xemit-jvm-type-annotations for it to work...

See https://youtrack.jetbrains.com/issue/KT-13228

Sign up to request clarification or add additional context in comments.

1 Comment

Worked for me in Kotlin 1.8 setup and target Java version 17, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.