[Dbix-class] DBIx::Class::ResultClass::HashRefInflator and
JSON::XS expanding numbers as strings
Robert Rothenberg
robrwo at gmail.com
Mon Mar 18 13:25:28 GMT 2013
On 15/03/13 11:16 Peter Rabbitson wrote:
> On Fri, Mar 15, 2013 at 09:48:13AM +0000, Robert Rothenberg wrote:
>> I have a PostgreSQL database that I run queries on, then use
>>
>> $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
>>
>> and send [ $rs->all ] to JSON::XS for serialization in a RESTful interface.
>>
>> It works well, except that numeric values are being translated into strings
>> instead of numbers.
>>
>> This doesn't happen with integers, because I cast the column as "::int" and
>> the system just does the right thing. But when I cast numeric columns as
>> "::numeric", they still come out as strings.
>>
>> I'm at the point where I want to write my own HashRefInflator, but I don't
>> understand what arguments the inflate_result method expects.
>
> The new trial series [1] (which I *really* hope you've tested [2])
I've not had the time to test the new version. :(
> contain new tests [3] describing this particular API in detail.
The description of the API looks rather opaque.
So... does it inflate column values to scalars, and joined tables to hash
references?
> Additions to the DBIC documentation would be absolutely awesome if you
> can provide these as you learn.
>
> Cheers!
>
> [1] http://lists.scsys.co.uk/pipermail/dbix-class/2013-February/011109.html
> [2] https://twitter.com/dbix_class/status/310776127885041664
> [3] https://github.com/dbsrgits/dbix-class/blob/topic/constructor_rewrite/t/resultset/inflate_result_api.t
More information about the DBIx-Class
mailing list