Re: JSON: id serializing as _id

59 views
Skip to first unread message

rktoomey

unread,
Jul 10, 2012, 11:48:20 PM7/10/12
to scala-salat
Hi Zafer,

as memory serves you're using the default salat play plugin context,
which automatically remaps id to _id. So this would be by design.
(If you remove that mapping "id" will be serialized as "id" , although
if you're persisting to mongo this is not recommended!)

Here's an issue created to look into a more nuanced solution:
https://github.com/novus/salat/issues/42

Best,
Rose

On Jul 10, 11:42 pm, mzafer <m.za...@tambolin.com> wrote:
> Hi Rose,
>
> Below is my case class and even though I have key field as "id", when I
> call toCompactJson() the generated JSON has that attribute as "_id". Not
> sure if this is be design or defect. If by design  how can I have it as
> "id" in the generated JSON. Also FYI, I am using "objectIdStrategy =
> StringObjectIdStrategy"
>
> case class Item(
> @Key("_id") id: ObjectId = new ObjectId,
>         listId:ObjectId,
>         name:String,
>         webUrl: String
>         )
>
> [debug] application - Saved Item
> :{"_id":"4ffcf55a05996a1bfb17f69b","listId":"4ffcee5e0599d6dd9dcae753","nam e":"Zafer
> Mohamed 1","webUrl":"zafer.com"}
>
> Thanks
> Zafer
Reply all
Reply to author
Forward
0 new messages