diff --git a/scripts/appendJsonSerializeCode.pl b/scripts/appendJsonSerializeCode.pl index 967ca838..7eb2ade1 100644 --- a/scripts/appendJsonSerializeCode.pl +++ b/scripts/appendJsonSerializeCode.pl @@ -13,7 +13,13 @@ my $filepath = "lib/net/authorize/api/contract/v1/"; my $filename = "$filepath"."$_"; my $text = `cat $filename`; - my $sub = `cat scripts/appendJsonSerializeCode.txt`; + my $sub = ""; + + if ($text =~ /(?^pm:\nclass \w+ extends )/) { + $sub = `cat scripts/appendJsonSerializeSubClassCode.txt`; + } else { + $sub = `cat scripts/appendJsonSerializeCode.txt`; + } $text =~ s|(.+)}|$1$sub|xms; diff --git a/scripts/appendJsonSerializeCode.txt b/scripts/appendJsonSerializeCode.txt index 9b849b7c..a01f6814 100755 --- a/scripts/appendJsonSerializeCode.txt +++ b/scripts/appendJsonSerializeCode.txt @@ -25,12 +25,7 @@ } } } - if (get_parent_class() == ""){ - return $values; - } - else{ - return array_merge(parent::jsonSerialize(), $values); - } + return $values; } } \ No newline at end of file diff --git a/scripts/appendJsonSerializeSubClassCode.txt b/scripts/appendJsonSerializeSubClassCode.txt new file mode 100644 index 00000000..1fa0379a --- /dev/null +++ b/scripts/appendJsonSerializeSubClassCode.txt @@ -0,0 +1,31 @@ + // Json Serialize Code + public function jsonSerialize(){ + $values = array_filter((array)get_object_vars($this), + function ($val){ + return !is_null($val); + }); + $mapper = \net\authorize\util\Mapper::Instance(); + foreach($values as $key => $value){ + $classDetails = $mapper->getClass(get_class() , $key); + if (isset($value)){ + if ($classDetails->className === 'Date'){ + $dateTime = $value->format('Y-m-d'); + $values[$key] = $dateTime; + } + else if ($classDetails->className === 'DateTime'){ + $dateTime = $value->format('Y-m-d\TH:i:s\Z'); + $values[$key] = $dateTime; + } + if (is_array($value)){ + if (!$classDetails->isInlineArray){ + $subKey = $classDetails->arrayEntryname; + $subArray = [$subKey => $value]; + $values[$key] = $subArray; + } + } + } + } + return array_merge(parent::jsonSerialize(), $values); + } + +} \ No newline at end of file