Using javax.validation.constraints @Annotations in GOSU

185 views
Skip to first unread message

Will Hu

unread,
May 15, 2017, 6:05:13 AM5/15/17
to gosu-lang
Hi Guys...
I am trying to use some data validation annotations in gosu DTO model..
@Length(min=1, max=9)
public var lastName: String

It looks like it does not support doing like @Length(min=1, max=9) or @Size(min=1).
Howver it works with:
@Max(9)
public var size : int

@NotNull
public var lastName : String

Wondering what I may do to use @Length, @Size, etc?
Thanks.

Kyle Moore

unread,
May 15, 2017, 10:02:36 AM5/15/17
to gosu-lang
Hi Will. When setting arguments to annotations you need to use named argument syntax, like this:

@Length(:min=1, :max=9)
public var lastName : String

Also note that if an annotations wants an array of Strings or primitives, make sure to wrap the values with the list initializer {} and they'll be coerced to an array.

There is a small section on "Named Arguments & Default Parameters" here: https://gosu-lang.github.io/docs.html

Good luck,

Kyle

Will Hu

unread,
May 22, 2017, 8:02:19 AM5/22/17
to gosu-lang
Thanks Kyle, sorry our current version does not support named argument syntax for annotations.. (But it works for functions)..ANyway. I may rebuild a gosu version annotations to implement @Length functionality. Thanks very much!
Reply all
Reply to author
Forward
0 new messages