forked from loafle/openapi-generator-original
Perl: Fix JSONization of ArrayObjects (#12896)
* Perl: fix object to json * generate samples * add test case
This commit is contained in:
parent
0b80444b56
commit
75895e18bc
@ -111,6 +111,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,6 +152,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,6 +152,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,6 +161,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,6 +161,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,6 +155,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,6 +152,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,6 +152,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,6 +152,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,6 +152,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,6 +152,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,6 +152,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,6 +153,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ sub _to_json_primitives {
|
||||
return $data->rfc3339;
|
||||
}
|
||||
return $data .q();
|
||||
} else { # hash (model), In this case, the TO_JSON of the $data object is executed
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use Test::More tests => 52;
|
||||
use Test::More tests => 56;
|
||||
use Test::Exception;
|
||||
|
||||
use lib 'lib';
|
||||
@ -171,3 +171,17 @@ like $order_to_json, qr/2020-11-06T09:20:48Z/, '$order{shipDate} to date-time fo
|
||||
like $order_to_json, qr/"101112"/, '$order{status} is number. But json type is string';
|
||||
|
||||
like $order_to_json, qr/false/, '$order{complete} is number. But json type is boolean';
|
||||
|
||||
my $pet_object = WWW::OpenAPIClient::Object::Pet->new->from_hash({
|
||||
tags => [
|
||||
WWW::OpenAPIClient::Object::Tag->new->from_hash({id => 123, name => 1000}),
|
||||
WWW::OpenAPIClient::Object::Tag->new->from_hash({id => 456, name => 'test2'}),
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
my $pet_object_to_json = JSON->new->convert_blessed->encode($pet_object);
|
||||
like $pet_object_to_json, qr/\"id\":123/, '$pet_object->tags->[0]->id';
|
||||
like $pet_object_to_json, qr/\"name\":\"1000\"/, '$pet_object->tags->[0]->name';
|
||||
like $pet_object_to_json, qr/\"id\":456/, '$pet_object->tags->[1]->id';
|
||||
like $pet_object_to_json, qr/\"name\":\"test2\"/, '$pet_object->tags->[1]->name';
|
Loading…
x
Reference in New Issue
Block a user