From 50fab154a40eb963c1855887196d8579b5453d84 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 26 Apr 2021 16:37:25 -0700 Subject: [PATCH] ToJSON: serialize string_columns to JSON If the column is undefined, then it should be an empty string according to your API spec. --- src/lib/Hydra/Component/ToJSON.pm | 4 ++++ src/lib/Hydra/Schema/Projects.pm | 2 +- t/Controller/projects.t | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/Hydra/Component/ToJSON.pm b/src/lib/Hydra/Component/ToJSON.pm index f6920943..e8f439de 100644 --- a/src/lib/Hydra/Component/ToJSON.pm +++ b/src/lib/Hydra/Component/ToJSON.pm @@ -18,6 +18,10 @@ sub TO_JSON { $json{$column} = $self->get_column($column); } + foreach my $column (@{$hint->{string_columns}}) { + $json{$column} = $self->get_column($column) // ""; + } + foreach my $column (@{$hint->{boolean_columns}}) { $json{$column} = $self->get_column($column) ? JSON::true : JSON::false; } diff --git a/src/lib/Hydra/Schema/Projects.pm b/src/lib/Hydra/Schema/Projects.pm index f8828428..e9857766 100644 --- a/src/lib/Hydra/Schema/Projects.pm +++ b/src/lib/Hydra/Schema/Projects.pm @@ -247,7 +247,7 @@ __PACKAGE__->many_to_many("usernames", "projectmembers", "username"); # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+4yWd9UjCyxxLZYDrVUAxA my %hint = ( - columns => [ + string_columns => [ "name", "displayname", "description", diff --git a/t/Controller/projects.t b/t/Controller/projects.t index 719d8dd8..02e60b45 100644 --- a/t/Controller/projects.t +++ b/t/Controller/projects.t @@ -25,11 +25,11 @@ my $projectinfo = request(GET '/project/tests', ok($projectinfo->is_success); is(decode_json($projectinfo->content), { - description => undef, + description => "", displayname => "", enabled => JSON::true, hidden => JSON::false, - homepage => undef, + homepage => "", jobsets => [], name => "tests", owner => "root"