nested Annotation List in Scala
Asked Answered
P

1

9

Help,

how do i do stuff like the following in Scala?

import org.hibernate.validator.constraints.ScriptAssert

@ScriptAssert.List({
    @ScriptAssert(script = "...", lang = "javascript"),
    @ScriptAssert(script = "...", lang = "javascript")})
Permanency answered 30/9, 2010 at 1:58 Comment(0)
M
9

The correct syntax is as follows (Array(...) for arrays, new Nested(..) for nested annotations):

import org.hibernate.validator.constraints.ScriptAssert

@ScriptAssert.List(Array(
  new ScriptAssert(script = "...", lang = "javascript"),
  new ScriptAssert(script = "...", lang = "javascript")))
class Test
Marty answered 30/9, 2010 at 7:10 Comment(4)
Did you try it? Using Scala 2.8, this works for me. I just got the syntax wrong in my initial answer, but now it's corrected.Marty
I did try (against scala 2.8 and hibernate validator), and it doesn't work. Did you try?Dehart
Your code gives "error: org.hibernate.validator.constraints.ScriptAssert does not have a constructor: new ScriptAssert(script = "...", lang = "javascript")))"Dehart
You need to put validation-api into the classpath. Here's the command I used for compiling the thing: ~/scala/dist/bin/scalac -cp /Users/luc/Downloads/hib/hibernate-validator-4.1.0.Final.jar:/Users/luc/Downloads/hib/validation-api-1.0.CR5.jar test.scalaMarty

© 2022 - 2024 — McMap. All rights reserved.