File tree Expand file tree Collapse file tree 3 files changed +39
-7
lines changed Expand file tree Collapse file tree 3 files changed +39
-7
lines changed Original file line number Diff line number Diff line change 13
13
my $filepath = " lib/net/authorize/api/contract/v1/" ;
14
14
my $filename = " $filepath " ." $_ " ;
15
15
my $text = ` cat $filename ` ;
16
- my $sub = ` cat scripts/appendJsonSerializeCode.txt` ;
16
+ my $sub = " " ;
17
+
18
+ if ($text =~ / (?^pm:\n class \w + extends )/ ) {
19
+ $sub = ` cat scripts/appendJsonSerializeSubClassCode.txt` ;
20
+ } else {
21
+ $sub = ` cat scripts/appendJsonSerializeCode.txt` ;
22
+ }
17
23
18
24
$text =~ s | (.+)}| $1 $sub | xms ;
19
25
Original file line number Diff line number Diff line change 25
25
}
26
26
}
27
27
}
28
- if (get_parent_class() == ""){
29
- return $values;
30
- }
31
- else{
32
- return array_merge(parent::jsonSerialize(), $values);
33
- }
28
+ return $values;
34
29
}
35
30
36
31
}
Original file line number Diff line number Diff line change
1
+ // Json Serialize Code
2
+ public function jsonSerialize(){
3
+ $values = array_filter((array)get_object_vars($this),
4
+ function ($val){
5
+ return !is_null($val);
6
+ });
7
+ $mapper = \net\authorize\util\Mapper::Instance();
8
+ foreach($values as $key => $value){
9
+ $classDetails = $mapper->getClass(get_class() , $key);
10
+ if (isset($value)){
11
+ if ($classDetails->className === 'Date'){
12
+ $dateTime = $value->format('Y-m-d');
13
+ $values[$key] = $dateTime;
14
+ }
15
+ else if ($classDetails->className === 'DateTime'){
16
+ $dateTime = $value->format('Y-m-d\TH:i:s\Z');
17
+ $values[$key] = $dateTime;
18
+ }
19
+ if (is_array($value)){
20
+ if (!$classDetails->isInlineArray){
21
+ $subKey = $classDetails->arrayEntryname;
22
+ $subArray = [$subKey => $value];
23
+ $values[$key] = $subArray;
24
+ }
25
+ }
26
+ }
27
+ }
28
+ return array_merge(parent::jsonSerialize(), $values);
29
+ }
30
+
31
+ }
You can’t perform that action at this time.
0 commit comments