I ended up moving the issue out of the jsonified method as Domhnall suggested which is working nicely and may have some extra benefits.
Many thanks to all. Domhnall Walsh wrote: > Well, maybe you should consider processing the tuple you plan to > return somehow to change the datetimes and Decimals to something more > palatable to @jsonify before returning it (via the decorator). If your > controller action is only returning JSON, then this shouldn't be a > problem? > > Domhnall. > > 2009/4/30 Uwe Feldtmann <[email protected] > <mailto:[email protected]>> > > Thanks Domhnall. > > Not sure if it will help as I'm using the jsonify decorator on a > method in the controller and it is what is failing when attempting > to wrap the result set. > > I managed to get the dates to work out by simply checking for data > type and then assigning in the controller. > > Decimals on the other hand are not working for me. There doesn't > appear to be a way to extract the value of a Decimal into another > variable without copying the entire object. > > Any suggestions or pointers greatly appreciated. > > Domhnall Walsh wrote: >> HI: >> >> This might give you a start: >> >> import simplejson >> >> class FancyEncoder(simplejson.JSONEncoder): >> """ >> Handle datetime objects. >> """ >> >> def default(self, obj): >> if isinstance(obj, datetime.datetime): >> return obj.isoformat() >> >> # Add more type-specific handlers here, for example for >> Decimals >> >> return simplejson.JSONEncoder.default(self, obj) >> >> json = simplejson.dumps(data_to_encode, cls=FancyEncoder) >> >> As you can see it replaces the datetimes with their ISO format >> representations as strings. >> >> Hope this helps, >> Domhnall. >> >> >> >> 2009/4/30 Uwe Feldtmann <[email protected] >> <mailto:[email protected]>> >> >> Hi all. >> >> I've been struggling with a controller that gets a result set >> from a database and should simply return that result set as >> json data and I keep getting this traceback >> >> ||TypeError: Decimal("0.00") is not JSON serializable >> >> the data returned from the db is: >> (1492, 'BAKER', 'MR. AND MRS BAKER', Decimal("843.50"), >> Decimal("5000.00"), Decimal("0.00"), datetime.date(1998, 8, >> 24), datetime.date(1998, 8, 31)) >> >> Is this an issue with @jsonify or am I missing something? >> >> >> I am using simplejson-2.0.8 and py2.5 >> >> Thanks in advance. >> >> >> >> >> >> -- >> Quidquid latine dictum sit, altum sonatur. >> (Whatever is said in Latin sounds profound) >> >> > > > > > > -- > Quidquid latine dictum sit, altum sonatur. > (Whatever is said in Latin sounds profound) > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
