@@ -63,13 +63,32 @@ public function __construct(array $raw, array $locales = ['en'])
6363
6464 public function jsonSerialize (): ?array
6565 {
66- return [
67- 'continent ' => $ this ->continent ->jsonSerialize (),
68- 'country ' => $ this ->country ->jsonSerialize (),
69- 'maxmind ' => $ this ->maxmind ->jsonSerialize (),
70- 'registered_country ' => $ this ->registeredCountry ->jsonSerialize (),
71- 'represented_country ' => $ this ->representedCountry ->jsonSerialize (),
72- 'traits ' => $ this ->traits ->jsonSerialize (),
73- ];
66+ $ js = [];
67+ $ continent = $ this ->continent ->jsonSerialize ();
68+ if (!empty ($ continent )) {
69+ $ js ['continent ' ] = $ continent ;
70+ }
71+ $ country = $ this ->country ->jsonSerialize ();
72+ if (!empty ($ country )) {
73+ $ js ['country ' ] = $ country ;
74+ }
75+ $ maxmind = $ this ->maxmind ->jsonSerialize ();
76+ if (!empty ($ maxmind )) {
77+ $ js ['maxmind ' ] = $ maxmind ;
78+ }
79+ $ registeredCountry = $ this ->registeredCountry ->jsonSerialize ();
80+ if (!empty ($ registeredCountry )) {
81+ $ js ['registered_country ' ] = $ registeredCountry ;
82+ }
83+ $ representedCountry = $ this ->representedCountry ->jsonSerialize ();
84+ if (!empty ($ representedCountry )) {
85+ $ js ['represented_country ' ] = $ representedCountry ;
86+ }
87+ $ traits = $ this ->traits ->jsonSerialize ();
88+ if (!empty ($ traits )) {
89+ $ js ['traits ' ] = $ traits ;
90+ }
91+
92+ return $ js ;
7493 }
7594}
0 commit comments