Skip to content

macros: Key annotation#140

Merged
sgodbillon merged 1 commit intoReactiveMongo:masterfrom
edofic:master
Dec 8, 2013
Merged

macros: Key annotation#140
sgodbillon merged 1 commit intoReactiveMongo:masterfrom
edofic:master

Conversation

@edofic
Copy link
Contributor

@edofic edofic commented Dec 6, 2013

added Key annotation and corresponding support in macros

example

case class Website(@Key("_id") url: String, content: Content)

maps url in case class to field _id in BSON in the generated handler

sgodbillon added a commit that referenced this pull request Dec 8, 2013
@sgodbillon sgodbillon merged commit 2e9cfc6 into ReactiveMongo:master Dec 8, 2013
@sgodbillon
Copy link
Member

Thanks!

@melentye
Copy link

Any idea why it might not work on the following case class when I insert an instance to a mongo collection?

Instead of using identityId it generates an _id field with uuid. If I rename identityId parameter to _id it works as expected.

import securesocial.core._
import securesocial.core.IdentityId
import play.api.libs.json.Json
import reactivemongo.bson.Macros.Annotations.Key

case class User(@Key("_id") identityId: IdentityId, firstName: String, lastName: String, fullName: String, email: Option[String],
                avatarUrl: Option[String], authMethod: AuthenticationMethod,
                oAuth1Info: Option[OAuth1Info] = None,
                oAuth2Info: Option[OAuth2Info] = None,
                passwordInfo: Option[PasswordInfo] = None) extends Identity

object User {
  object Implicits {
    implicit val identityIdFormat = Json.format[IdentityId]
    implicit val authenticationMethodFormat = Json.format[AuthenticationMethod]
    implicit val oAuth1InfoFormat = Json.format[OAuth1Info]
    implicit val oAuth2InfoFormat = Json.format[OAuth2Info]
    implicit val passwordInfoFormat = Json.format[PasswordInfo]
    implicit val userFormat = Json.format[User]
  }
}

@sgodbillon
Copy link
Member

You are using json, not bson :) This PR only targets the embedded BSON library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants