File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -127,7 +127,31 @@ public function getChangedColumns(): array
127
127
*/
128
128
public function jsonSerialize (): array
129
129
{
130
- return $ this ->toArray ();
130
+ $ schema = static ::schema ();
131
+ if ($ schema ->hydrator ) {
132
+ return $ schema ->hydrator ->toArray ($ this );
133
+ }
134
+ $ result = [];
135
+ foreach ($ schema ->columns as $ columnName => $ column ) {
136
+ if ($ this ->isNew () && !$ column ->isInitialized ($ this )) {
137
+ continue ;
138
+ }
139
+ $ value = $ this ->{$ columnName };
140
+ if ($ value === null && $ column ->isNullable ) {
141
+ $ result [$ columnName ] = null ;
142
+ } else {
143
+ if ($ column instanceof Columns \EntityColumn) {
144
+ $ result [$ columnName ] = $ value ->jsonSerialize ();
145
+ } elseif ($ column instanceof Columns \ArrayColumn) {
146
+ $ result [$ columnName ] = $ value ;
147
+ } elseif ($ column instanceof Columns \EntityListColumn) {
148
+ $ result [$ columnName ] = array_map (fn ($ item ) => $ item ->jsonSerialize (), $ value );
149
+ } else {
150
+ $ result [$ columnName ] = $ column ->uncast ($ value );
151
+ }
152
+ }
153
+ }
154
+ return $ result ;
131
155
}
132
156
133
157
/**
You can’t perform that action at this time.
0 commit comments