0

What I tried:

I tried around one and half day, not resolved yet.

I tried by creating MyEntityTemp entity similar to MyEntity and written a converter. Even I am getting two id fields. Please need help to resolve.

I found some of MyEntity inherited classes have id field, so I removed that inherited classes even I am getting same problem.

case class MYEntity (
   @Key("_id") id: String =ObjectId(),
//  id: String,   // I tried like this also, even I am getting two ids
  regionId: String,
  zoneId: String)

object ObjectId {
  def apply(): String = new org.bson.types.ObjectId().toString
}

Using: Scala 2.10.5 Salat 1.9.9 json4s-native 3.3.0

Error:

Need to get like this:

{
    "_id" : "5411b214ebb290b62281c845",
}

But getting

{
    "_id" : ObjectId("58f5eabb0c7443adcca88e57"),
    "id" : "5411b214ebb290b62281c845",
}

Could you please help me, why I am getting like this.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Sri Manga
  • 561
  • 1
  • 5
  • 8

1 Answers1

0

I worked for two days on it and tried with multiple ways even getting same problem. Finally I tried to do with Casbah mongo api instead of Salat.

I build a MongoDBObject, I replaced with id field name with _id and saved in mongoDB. Now it happening what I expected.

Sri Manga
  • 561
  • 1
  • 5
  • 8
  • Will wondering about this question and your answer. Did you understand that Mongo will assign an ID field having name _id of type "ObjectId" even if your case class does not have such a field? – noahlz Apr 24 '17 at 18:50