@@ -, +, @@ --- Koha/Object.pm | 5 ++++- t/db_dependent/Koha/Object.t | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) --- a/Koha/Object.pm +++ a/Koha/Object.pm @@ -22,6 +22,7 @@ use Modern::Perl; use Carp; use Mojo::JSON; +use Scalar::Util qw( looks_like_number ); use Try::Tiny; use Koha::Database; @@ -241,7 +242,9 @@ sub TO_JSON { ? Mojo::JSON->true : Mojo::JSON->false; } - elsif ( _numeric_column_type( $columns_info->{$col}->{data_type} ) ) { + elsif ( _numeric_column_type( $columns_info->{$col}->{data_type} ) + and looks_like_number( $unblessed->{$col} ) + ) { # TODO: Remove once the solution for # https://rt.cpan.org/Ticket/Display.html?id=119904 --- a/t/db_dependent/Koha/Object.t +++ a/t/db_dependent/Koha/Object.t @@ -161,7 +161,7 @@ subtest 'discard_changes' => sub { subtest 'TO_JSON tests' => sub { - plan tests => 7; + plan tests => 8; $schema->storage->txn_begin; @@ -169,6 +169,7 @@ subtest 'TO_JSON tests' => sub { my $borrowernumber = $builder->build( { source => 'Borrower', value => { lost => 1, + sms_provider_id => undef, gonenoaddress => 0, updated_on => $dt, lastseen => $dt, } })->{borrowernumber}; @@ -185,6 +186,8 @@ subtest 'TO_JSON tests' => sub { ok( $gonenoaddress->isa('JSON::PP::Boolean'), 'Boolean attribute type is correct' ); is( $gonenoaddress, 0, 'Boolean attribute value is correct (false)' ); + is( $patron->TO_JSON->{sms_provider_id}, undef, 'Undef values should not be casted to 0' ); + ok( !isvstring($patron->borrowernumber), 'Integer values are not coded as strings' ); my $rfc3999_regex = qr/ --