Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array of annotations as parameter to an annotation, in Scala

There are plenty of questions about passing an array as a parameter to an annotation, this is not a dupe of those.

I would like to use a Java-land annotation that takes an array of annotations as a parameter, e.g.

@ManagedOperation
@ManagedOperationParameters({
  @ManagedOperationParameter(name="start"),
  @ManagedOperationParameter(name="end")
})
def stuff(start: String, end: String): Unit = ???

But this is not valid syntax in Scala, nor is

@ManagedOperation
@ManagedOperationParameters(Array(
  @ManagedOperationParameter(name="start"),
  @ManagedOperationParameter(name="end")
))
def stuff(start: String, end: String): Unit = ???

so what is the correct way to do this, if it is even possible?

BTW, I even checked all of github to see if any Scala devs are using this (Spring JMX) annotation.

like image 283
fommil Avatar asked May 07 '15 15:05

fommil


1 Answers

In scala the inner annotation should be used as regular type:

@JsonTypeInfo(
  use = JsonTypeInfo.Id.NAME,
  include = JsonTypeInfo.As.PROPERTY,
  property = "moduleType",
  defaultImpl = classOf[PuppetModule]
)
@JsonSubTypes(Array(
  new Type(value = classOf[PuppetModule], name = "puppet"),
  new Type(value = classOf[PluginModule], name = "plugin")
))
trait Module {
  val moduleType: String = if (this.isInstanceOf[PuppetModule]) "puppet" else "plugin"
  val nodes: List[String] = List[String]()
}
like image 52
igreenfield Avatar answered Oct 24 '22 06:10

igreenfield