On Wed, Feb 29, 2012 at 09:22:28PM -0800, Cosmia Luna wrote:
> I want to to return some SQLAlchemy object to the json renderer, of course
> it didn't work.
> Can I add a method to the Base like:
> 
> class Base(object):
>     def __jsonSerialize__(self):
>         pass # return a dict-like object
> 
> Base=declarative_base(cls=Base)
> 
> Or I have to write a renderer called ejson(extendable json renderer) or
> some other wrapping the default json renderer?

Sorry for self-advertisement, but I've wrote a small utility to solve this kind
of problems -- jsonpublish[1]. Code looks like this:

  class Base(object):
    pass
 
  from jsonpublish import register_adapter, dumps
 
  @register_adapter(Base)
  def adapt_base(b):
    return {} # adapt Base object to json-encodable structure
 
  dumps(Base()) # now it works!

See docs[1] for more info.

[1]: http://jsonpublish.readthedocs.org/en/latest/index.html

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to