0

I have a case class that looks like this:

import com.novus.salat.annotations.raw.Key
import org.bson.types.ObjectId

case class Users(
                  _id: ObjectId,
                  email: String,
                  password: String,
                  firstName: String,
                  lastName: String,
                  company: Option[String],
                  position: Option[String],
                  enabled: Boolean)

And a simple SalatDAO:

import com.novus.salat.dao.SalatDAO
import org.bson.types.ObjectId
import com.novus.salat.global._

object UsersDAO extends SalatDAO[Users, ObjectId](
  collection = MongoFactory.getCollection("usersCollection"))

So now I want to change "_id" to "id". I thought that Salat @Key annotation is indeed for that purpose. So I write:

...
@Key("_id") id: ObjectId,
...

And when I try UsersDAO.find(MongoDBObject.empty) I get an exception

java.lang.NoSuchMethodException: com...Users$.apply$default$1()

What interesting - if I do the same thing but for another class where "id: String" I get this exception

java.lang.Exception: class com...AnotherClass requires value for 'id'

Can anyone throw sunshine on that please?

invis
  • 1,078
  • 2
  • 14
  • 26

1 Answers1

1

you need to fix your import. Use

import com.novus.salat.annotations._

to properly target the @Key annotation to the getter.

See https://github.com/salat/salat/wiki/Annotations

prasinous
  • 798
  • 3
  • 6
  • Thanks! Works fine now. Actually @EnumAs worked fine with just { import com.novus.salat.EnumStrategy import com.novus.salat.annotations.EnumAs } – invis Jun 29 '15 at 14:31
  • Sorry, I know, it's not consistent. I should get rid of the `@getter` targeting requirements for the rest of the annotations, it's been a pain to support. – prasinous Jun 29 '15 at 19:01