Re: Digest for bowler-users@googlegroups.com - 3 Messages in 1 Topic

3 views
Skip to first unread message

Mrityunjay Kant

unread,
Dec 24, 2011, 8:14:19 AM12/24/11
to bowler...@googlegroups.com
Hi,

Thanks for the suggestions. I ended up doing the same; defining my own Renderer and plugging it in using BowlerConfigurator.

I think it would be good to have a utility class/object that can include additional Serializers without having to go though all the hoops. I'll check the Bowler code and see if I can add something for it.

Happy Holidays and Merry Christmas.
Mrityunjay

On Sat, Dec 24, 2011 at 11:13 AM, <bowler...@googlegroups.com> wrote:

Group: http://groups.google.com/group/bowler-users/topics

    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.


Wille Faler

unread,
Dec 24, 2011, 11:54:39 AM12/24/11
to bowler...@googlegroups.com
Hi,
I'd be happy to look at your thoughts in a pull request! I definitely know this is an area that needs addressing (I've bumped my own head into it a couple of times), though it shouldn't be too hard to fix.
Reply all
Reply to author
Forward
0 new messages