Group: http://groups.google.com/group/bowler-users/topics
- ObjectId getting rendered as empty list [3 Updates]
Mrityunjay Kant <kant.mr...@gmail.com> Dec 23 02:33AM -0800
Hi,
I have the following case class for storage in MongoDb:
case class Item(_id : ObjectId, name : String, value : String)
When I return this case object back to client I need to include value
for _id field. However, the _id column is being returned as an empty
list in Json output instead of its actual value.
{"_id":{},"name":"Id Test","value":"id test"}
Any pointers on how this can be fixed will be greatly appreciated.
Mrityunjay Kant <kant.mr...@gmail.com> Dec 23 06:26AM -0800
Update: I tried using custom serializer for it but for some reason it
doesn't get called!
class ObjectIdSerializer extends Serializer[ObjectId] {
private val Class = classOf[ObjectId]
def deserialize(implicit format: Formats) = {
case (TypeInfo(Class, _), json) => json match {
case JObject(JField("_id", JString(s)) :: Nil) => new
ObjectId(s)
case x => throw new MappingException("Can't convert " + x + "
to ObjectId")
}
}
def serialize(implicit format: Formats) = {
case x: ObjectId => { println("\t @@@@@@@@Custom Serializer was
called!"); JObject(JField("_id", JString(x.toString)) :: Nil)}
}
}
implicit val formats = DefaultFormats + new ObjectIdSerializer
Wille Faler <wille...@gmail.com> Dec 23 07:24PM
Hi,
I suspect this is because the Serializer doesn't get set in the
RenderStrategy:
https://github.com/wfaler/Bowler/blob/master/core/src/main/scala/org/bowlerframework/view/DefaultRenderStrategy.scala
I think the fix for this is to make sure the JSONRenderStrategy in the same
package can take an arbitrary number of serializers in it's constructor,
then allowing this to be set via the RenderStrategy, and set a
RenderStrategy with your configurations in the BowlerConfigurator.
If you want to fix it (should be relatively simple), I'd be happy to accept
a pull request that sorts this out (the above mentioned are the three main
places I think that you might want to look at).
Otherwise, please raise a ticket and I'll fix it next week, but at the
moment I am indisposed due to Christmas for a few days.
..also tempting you to fix it, because I'd love to see some more
contributions. ;)
You received this message because you are subscribed to the Google Group bowler-users.
You can post via email.
To unsubscribe from this group, send an empty message.
For more options, visit this group.