@@ -202,7 +202,7 @@ public function getJsonSerializeCode(): string
202
202
return '' ;
203
203
}
204
204
$ isIncluded = false ;
205
- $ format = " jsonSerialize(true) " ;
205
+ $ format = ' jsonSerialize(true) ' ;
206
206
} else {
207
207
$ isIncluded = $ this ->findAnnotation (Annotation \JsonInclude::class) !== null ;
208
208
/** @var Annotation\JsonFormat|null $jsonFormat */
@@ -220,20 +220,37 @@ public function getJsonSerializeCode(): string
220
220
$ index = $ jsonKey ? $ jsonKey ->key : $ this ->namingStrategy ->getJsonProperty ($ this );
221
221
$ getter = $ this ->getGetterName ();
222
222
if (!$ this ->isCompulsory ()) {
223
- $ code = "\$array[' $ index'] = ( \$object = \$this-> $ getter()) ? \$object-> $ format : null; " ;
223
+ $ recursiveCode = "\$array[' $ index'] = ( \$object = \$this-> $ getter()) ? \$object-> $ format : null; " ;
224
+ $ lazyCode = "\$array[' $ index'] = ( \$object = \$this-> $ getter()) ? {$ this ->getLazySerializeCode ('$object ' )} : null; " ;
224
225
} else {
225
- $ code = "\$array[' $ index'] = \$this-> $ getter()-> $ format; " ;
226
+ $ recursiveCode = "\$array[' $ index'] = \$this-> $ getter()-> $ format; " ;
227
+ $ lazyCode = "\$array[' $ index'] = {$ this ->getLazySerializeCode ("\$this-> $ getter() " )}; " ;
226
228
}
227
- if (!$ isIncluded ) {
229
+
230
+ if ($ isIncluded ) {
231
+ $ code = $ recursiveCode ;
232
+ } else {
228
233
$ code = <<<PHP
229
- if (! \$stopRecursion) {
230
- $ code
231
- };
234
+ if ( \$stopRecursion) {
235
+ $ lazyCode
236
+ } else {
237
+ $ recursiveCode
238
+ }
232
239
PHP ;
233
240
}
234
241
return $ code ;
235
242
}
236
243
244
+ private function getLazySerializeCode (string $ propertyAccess ): string
245
+ {
246
+ $ rows = [];
247
+ foreach ($ this ->getForeignKey ()->getUnquotedForeignColumns () as $ column ) {
248
+ $ columnGetterName = 'get ' . TDBMDaoGenerator::toCamelCase ($ column );
249
+ $ rows [] = "' $ column' => $ propertyAccess-> $ columnGetterName() " ;
250
+ }
251
+ return '[ ' . implode (', ' , $ rows ) . '] ' ;
252
+ }
253
+
237
254
/**
238
255
* The code to past in the __clone method.
239
256
* @return null|string
0 commit comments