5

I wanted to add encryption to my application using the Jasypt library. Their integration page says to add a @TypeDef annotation:

"Define the encryption type with a @TypeDef annotation, which could be either inside the persisted entity class or inside a @TypeDefs declaration in a separate package-info.java file":

@TypeDef(
    name="encryptedString", 
    typeClass=EncryptedStringType.class, 
    parameters= {
        @Parameter(name="encryptorRegisteredName", value="myHibernateStringEncryptor")
    }
)

However, I noticed that when I tried this on a groovy file, I received a syntax error.

"Groovy:unexpected token: } @ line 12, column 3."

When I copy and pasted the exact code into a java file it works fine. If I remove the parameters argument it works, I'm thinking that the parameters { } argument is being interpreted as a closure by groovy.

EDIT: I ended up moving the annotation to package-info.java but I still want to know why this doesn't work in groovy.

Mike R
  • 4,448
  • 3
  • 33
  • 40

1 Answers1

6

The problem probably resides in the parameters block:

parameters= {
    @Parameter(name="encryptorRegisteredName", value="myHibernateStringEncryptor")
}

Whereas curly-braces can be used in java to specify a static-initialization block for arrays, in groovy the curly-brace is the grammar token for a closure, which isn't what you want here. I imagine the following might work:

parameters= [
    @Parameter(name="encryptorRegisteredName", value="myHibernateStringEncryptor")
]

Note the hard-braces, which is groovy's token for anonymously-created lists/maps.

billjamesdev
  • 14,554
  • 6
  • 53
  • 76