[Catalyst] Noob hoping for help encoding mysql datetime fields for JSON

Steve Seremeth steve.seremeth at dealer.com
Thu Mar 15 21:38:07 GMT 2012

Hello -

I am semi new to Perl and Catalyst.  I have walked through the Catalyst tut=
orial a couple times and have also picked up a couple books and done much g=
oogling that always seem to get me close but leave me hanging.

Have been looking at tons of docs for catalyst::controller::rest and cataly=
st::view::json amongst many others and can't find joy.

Anyway -- I think I would be on the right track if someone solved this basi=
c inquiry:

Working from this example:
http://www.catalystframework.org/calendar/2009/22# An AJAX CRUD Interface w=
ith Catalyst and jQuery<http://www.catalystframework.org/calendar/2009/22#%=

which I have working fine, fwiw...

How would you expose the "created" column from the db (schema came from her=
e: http://search.cpan.org/~bobtfish/Catalyst-Manual-5.9003/lib/Catalyst/Man=
anual-5.9003/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod> and is, in this=
 example, a sqlite TIMESTAMP col) in the JSON generated by the API controll=
er's grid_POST method?

If I simply add the column to the API controller here:

    $data{rows}  =3D [
        map { +{
            id =3D> $_->id,
            cell =3D> [
        } } $paged_rs->all

The app throws this:

Content-Type application/json had a problem with your request.
encountered object '2012-02-29T17:16:27', but neither allow_blessed enabled=
 nor TO_JSON method available on it at /usr/local/share/perl/5.12.4/Catalys=
t/Action/Serialize/JSON.pm line 39.

And I realize I'm not serializing the timestamp appropriately (and how data=
 with colons are bound to cause issues in JSON)...  but this simple thing i=
s what I haven't been able to solve.

Any guidance greatly appreciated.

Thanks -


P.S.  For penance I will create some documentation of the working example a=
nd check it in somewhere useful or host a living doc on one of my websites =
to help others.

Steve Seremeth | Release Engineer
steve.seremeth at dealer.com<mailto:{Message%20Sender}>
V : 877.327.8422 x 1391

[Like Dealer.com]<http://www.facebook.com/DealerDotCom> [Follow Dealer.com]=
 <https://twitter.com/#!/DealerDotCom>  [Follow Dealer.com] <http://www.lin=
kedin.com/company/dealer.com>  [Dealer.com Channel] <http://www.youtube.com=
/user/DealerDotCom>  [Dealer.com Blog] <http://www.dealer.com/blog.htm>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120315/8f8d4=

More information about the Catalyst mailing list