[Koha-bugs] [Bug 17932] Koha::Object should provide a TO_JSON method

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Tue Jan 24 14:52:06 CET 2017


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=17932

Tomás Cohen Arazi <tomascohen at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #59431|0                           |1
        is obsolete|                            |

--- Comment #4 from Tomás Cohen Arazi <tomascohen at gmail.com> ---
Created attachment 59498
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=59498&action=edit
Bug 17932: Add a TO_JSON method to Koha::Object(s)

Bug 17927 fixes data types on the current REST endpoints. If you
test those endpoints, you will notice trying to access them (for listing
or retrieving single objects yields a data type error. Notably on
booleans but also on integers.

Integers fail due to https://rt.cpan.org/Ticket/Display.html?id=119904
but it needs some global solution until there's a DBD::mysql release
backported to the supported distros. There's the option to use
http://search.cpan.org/~frew/DBIx-Class-Helpers-2.033002/lib/DBIx/Class/Helper/Row/NumifyGet.pm
to get the integer columns fixed as a workaround:

 __PACKAGE__->add_columns(
    borrowernumber => {
        data_type         => 'integer',
        is_nullable       => 0,
        is_numeric        => 1,
    }
);

I didn't find bug reports related to this (maybe because we don't use
warnings everywhere) But I don't think is worth going such a heavy
overhead.

A similar situation takes place for Boolean values. They need to be
prepared for JSON output. This could have been done using DBIx filters
as pointed out by Martin:

__PACKAGE__->filter_column(
    lost => {
       filter_to_storage => sub { $_[1] ? 1 : 0 },
       filter_from_storage =>
               sub { $_[1] ? Mojo::JSON->true :
                             Mojo::JSON->false }
       }
);

but this could have other consequences that are worth exploring on
another bug (i.e. it would mean we need to take care of every place
where this boolean data is used/set needs to handle this data types
nicely. Such would be the case if we were a Mojo-only app, but we
aren't. We use Koha::Obect(s) in the whole app. Period.

This patch adds the need to specify on the schema files, columns that
are actually boolean, because we have no way to detect them for now
(i.e. they are all tinyint, but we use tinyint for non-boolean stuff
 too).
So if this patch is accepted, we would need to specify boolean columns
like this:

__PACKAGE__->add_columns(
    '+lost' => {
        is_boolean => 1
    }
);

This patch adds a TO_JSON method for Koha::Object(s) to be used for
serializing Koha::Object-derived objects into JSON strings.

To test it (as Koha::Object(s) need to be instantiated) I provide tests
on top of the Koha::Patron(s) classes in the followup patches.

[1] Yes, we use TINYINT(1) for booleans, but from DBIC's perspective
there's no way to read the (1) in runtime.

Sponsored-by: ByWater Solutions

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list