On Aug 13, 2009, at 2:12 AM, Jorge Vargas wrote: > Your solution for this problem could work with the > "when" decorator but I don't see it as the best solution. Which > criteria will you use to strip all unwanted attributes from all > objects? It seems to me like a very big set of hasattr check that will > return false on all objects that don't have it and only true on a flew > that do.
> Wouldn't it be better to subclass the serializer and do things from > there? again which will be the criteria? Will anyone come up with an > example where this is needed? The case I was working with was serializing the lists from an AssociationProxy. I'm pretty new to TG, but it seems to me the default behavior isn't great, at least in TurboJson 1.2.1, skipping keys starting with _sa_ but including the private _AssociationProxy_* collections, which aren't really in a usable format. I think it should either skip the private proxy collection too, or include it in a usable form. Undoubtedly skipping it makes more sense as a default behavior. Maybe this is really a SA issue, because not all of their private keys start with _sa_, but it seems easy enough to fix at the turbojson level. My model only had one class that used an association proxy, but if you had a bunch of classes that had a reasonably finite set of objects in an association proxy (say <10 keywords each), I think that's a use case that justifies a global way to do it for a given project, such as the when decorator. And if they were all called "keywords", then it's only one hasattr to check. I hadn't thought about subclassing the whole serializer. I think that's a little bit more intimidating, but like I said, I'm pretty new to TG, so I'm still trying to absorb it all. In my case, subclassing would have made sense, because I wanted to take out something (_AssociationProxy_* keys) and I couldn't figure out how to do that in a when decorator without basically overriding the whole process anyway. I think the decorator syntax is nice and clean, and the best examples are in TurboJson it self: datetime, decimal and explicit. Presumably those are handled in TG 2.1 as well, so hopefully there's a nice way to subclass and override similar types of objects, such as a duration or a currency. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" 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/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

