[Dbix-class] RFC: DBIx::Class::JSON
Rob Kinyon
rob.kinyon at gmail.com
Thu Sep 14 15:31:24 CEST 2006
On 9/13/06, Nilson Santos Figueiredo Junior <acid06 at gmail.com> wrote:
> Relationships are also dumped.
> So if you've got A which has_many B, you'll get something like:
>
> A = {
> A_field1: 'value',
> A_field2: 'value',
> // etc
> relationship: [
> { B_field1: 'value', B_field2: 'value' },
> { B_field1: 'value', B_field2: 'value' }
> ]
> }
>
> In fact, this sort of thing was my main motivation behind the
> development of this component, since I've got arbitrarily nested
> relationships (in a parent-child scheme) which I needed available as
> JSON. In fact, there's a specific feature for this use case in the
> component.
That can be useful. But, that can make the JSON quite huge.
> Another nice thing is that it can easily acommodate having "custom
> renderers" for columns based on column_type or whatever. I actually
> tried implementing automatic DateTime -> JS Date object conversion,
> but I couldn't coerce JSON::Syck to drop the quotes. If I manage to
> get this one working, it'll be "the killer feature" (at least for me).
> ;-)
That's very useful.
> There's another silly feature that simplifies the generic use case:
> the possibility to define certain columns as being hidden from the
> JSON serialization by default. This is useful when you're serializing
> e.g. user objects but don't fields such as the user password to be
> serialized. Granted, this is one is all about lazyness.
You might want to look at how the Dojo does JSON serialization. What
it does is it looks for a json() method on the object and, if one
exists, it will serialize the return value from that. Otherwise, it
will serialize the object itself. A plugin that does that would be
very nice.
> And last, but not least: it looks a lot better to just call [%
> row.as_json %] from TT than any other method I could think of. In my
> book, syntatic sugar is important.
Sugar is hard to overrate. :-)
Thanks,
Rob
More information about the Dbix-class
mailing list