JSONifying DBIx::Class results

305 views
Skip to first unread message

Kartik Thakore

unread,
May 25, 2012, 2:18:30 PM5/25/12
to mojol...@googlegroups.com
Hi,

When I do:

my $job = $schema->resultset('Job')->create({ status => 'new', started => DateTime->now, runfile => $valid_lines } );
 $self->render( json => { msg => "File $name, $size byte is uploaded and job ".$job->id() ." is started.", job => $job} );

I get a response like so:

{"msg":"File model.t, 834 byte is uploaded and job 3 is started.","job":"Danna::Schema::Result::Job=HASH(0x36c8538)"}

How should I jsonify that object? 

Gabriel Vieira

unread,
May 25, 2012, 2:33:54 PM5/25/12
to mojol...@googlegroups.com
http://mojolicio.us/perldoc/Mojo/JSON helps?
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To post to this group, send email to mojol...@googlegroups.com.
> To unsubscribe from this group, send email to
> mojolicious...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mojolicious?hl=en.



--
Gabriel Vieira

Skye Shaw!@#$

unread,
May 25, 2012, 4:49:35 PM5/25/12
to mojol...@googlegroups.com
If your Mojolicious version is >= 2.86 you can add a TO_JSON method to your Job class.  This will be called by Mojo::JSON when it encounters your job object. 

Otherwise, you'd can try:

job => $job->get_columns
Reply all
Reply to author
Forward
0 new messages