Skip to content

[php][bug] Fix generic ObjectSerializer error when deserializing SomeClass[] data #7827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ class ObjectSerializer
}

if (strcasecmp(substr($class, -2), '[]') === 0) {
$data = is_string($data) ? json_decode($data) : $data;

$data = is_string($data) ? json_decode($data, true) : $data;
if (!is_array($data)) {
throw new \InvalidArgumentException("Invalid array '$class'");
}
Expand All @@ -279,8 +278,11 @@ class ObjectSerializer
}

if (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
$data = is_string($data) ? json_decode($data) : $data;
settype($data, 'array');
$data = is_string($data) ? json_decode($data, true) : $data;
if (!is_array($data)) {
throw new \InvalidArgumentException("Invalid array '$class'");
}

$inner = substr($class, 4, -1);
$deserialized = [];
if (strrpos($inner, ",") !== false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ public static function deserialize($data, $class, $httpHeaders = null)
}

if (strcasecmp(substr($class, -2), '[]') === 0) {
$data = is_string($data) ? json_decode($data) : $data;

$data = is_string($data) ? json_decode($data, true) : $data;
if (!is_array($data)) {
throw new \InvalidArgumentException("Invalid array '$class'");
}
Expand All @@ -289,8 +288,11 @@ public static function deserialize($data, $class, $httpHeaders = null)
}

if (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int]
$data = is_string($data) ? json_decode($data) : $data;
settype($data, 'array');
$data = is_string($data) ? json_decode($data, true) : $data;
if (!is_array($data)) {
throw new \InvalidArgumentException("Invalid array '$class'");
}

$inner = substr($class, 4, -1);
$deserialized = [];
if (strrpos($inner, ",") !== false) {
Expand Down