ToJSON: serialize string_columns to JSON

If the column is undefined, then it should be an empty string according to your
API spec.
This commit is contained in:
Cole Helbling 2021-04-26 16:37:25 -07:00
parent f0ede5f8b8
commit 50fab154a4
No known key found for this signature in database
GPG key ID: B37E0F2371016A4C
3 changed files with 7 additions and 3 deletions

View file

@ -18,6 +18,10 @@ sub TO_JSON {
$json{$column} = $self->get_column($column); $json{$column} = $self->get_column($column);
} }
foreach my $column (@{$hint->{string_columns}}) {
$json{$column} = $self->get_column($column) // "";
}
foreach my $column (@{$hint->{boolean_columns}}) { foreach my $column (@{$hint->{boolean_columns}}) {
$json{$column} = $self->get_column($column) ? JSON::true : JSON::false; $json{$column} = $self->get_column($column) ? JSON::true : JSON::false;
} }

View file

@ -247,7 +247,7 @@ __PACKAGE__->many_to_many("usernames", "projectmembers", "username");
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+4yWd9UjCyxxLZYDrVUAxA # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+4yWd9UjCyxxLZYDrVUAxA
my %hint = ( my %hint = (
columns => [ string_columns => [
"name", "name",
"displayname", "displayname",
"description", "description",

View file

@ -25,11 +25,11 @@ my $projectinfo = request(GET '/project/tests',
ok($projectinfo->is_success); ok($projectinfo->is_success);
is(decode_json($projectinfo->content), { is(decode_json($projectinfo->content), {
description => undef, description => "",
displayname => "", displayname => "",
enabled => JSON::true, enabled => JSON::true,
hidden => JSON::false, hidden => JSON::false,
homepage => undef, homepage => "",
jobsets => [], jobsets => [],
name => "tests", name => "tests",
owner => "root" owner => "root"