Repository navigation
Commit 966050d
committed
fix(writer): make field-level serializeFeatures agree across creators, formats and filters
Review round 1 found that the generation-time guards admitted field-level
features the interpreting machinery never aligned, so the two creators -
and the two output formats - disagreed:
R1-1: the three new guards admitted NullAsDefaultValue, but
FieldWriterEnum.write gates on WriteNulls only, so ASM wrote a null enum
the reflect creator omits, and int[]/long[] went through the no-arg
writeArrayNull(), which resolves []-vs-null from the context alone. The
enum gate is narrowed back to WriteNulls (both creators now omit it, as
they did before this branch), and int[]/long[] plus the six FieldWriter
array methods share one family mask - WriteNulls | NullAsDefaultValue |
WriteNullListAsEmpty, spelled once in FieldWriter.ARRAY_NULL_FEATURES -
and write the null through writeArrayNull(context | field), the same merge
the reflect creator performs in FieldWriterObject#write.
R1-2: the JSONB generator gated null-writing on the context-only
WRITE_NULLS var and default primitives on NOT_WRITE_DEFAULT_VALUE, so
field-level features were dead in JSONB (and zero float/double were always
written). Both guards now bake the field-level feature, mirroring the text
generators. A null enum in the direct JSONB path wrote through
JSONB.IO.writeEnum, which dereferences the value - now guarded; this also
fixes the same crash reachable with a context WriteNulls on main.
R1-3: ObjectWriterAdapter's filtered loop pre-skipped null fields with the
context-only isWriteNulls(), so attaching any filter silently dropped
annotated null fields. It now merges the field features, matching the
no-filter fast path.
R1-4: with the family mask above, WriteNullListAsEmpty-annotated arrays
write [] in ASM as they do in reflect. The Date gate stays WriteNulls-only
on both sides: the reflect creator drops a NullAsDefaultValue Date, so
widening the ASM gate would break - not restore - parity.
Issue7773 is extended to pin all of it: per-fixture creator parity in text
and JSONB, the filtered path, and the Date/boxed/String corner cases.
Signed-off-by: Rainmemery <152621457+Rainmemery@users.noreply.github.com>1 parent 2544a2c commit 966050d
4 files changed
Lines changed: 335 additions & 37 deletions
File tree
- core/src
- main/java/com/alibaba/fastjson2/writer
- test/java/com/alibaba/fastjson2/issues_7000
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
589 | 589 | | |
590 | 590 | | |
591 | 591 | | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
592 | 602 | | |
593 | 603 | | |
594 | | - | |
| 604 | + | |
| 605 | + | |
595 | 606 | | |
596 | 607 | | |
597 | 608 | | |
598 | | - | |
| 609 | + | |
599 | 610 | | |
600 | 611 | | |
601 | 612 | | |
| |||
633 | 644 | | |
634 | 645 | | |
635 | 646 | | |
636 | | - | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
637 | 654 | | |
638 | 655 | | |
639 | 656 | | |
| |||
683 | 700 | | |
684 | 701 | | |
685 | 702 | | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | 703 | | |
692 | | - | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
693 | 710 | | |
694 | 711 | | |
695 | 712 | | |
| 713 | + | |
696 | 714 | | |
697 | 715 | | |
698 | 716 | | |
| |||
728 | 746 | | |
729 | 747 | | |
730 | 748 | | |
731 | | - | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
732 | 756 | | |
733 | 757 | | |
734 | 758 | | |
| |||
741 | 765 | | |
742 | 766 | | |
743 | 767 | | |
744 | | - | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
745 | 775 | | |
746 | 776 | | |
747 | 777 | | |
| |||
754 | 784 | | |
755 | 785 | | |
756 | 786 | | |
757 | | - | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
758 | 794 | | |
759 | 795 | | |
760 | 796 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
602 | | - | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
603 | 607 | | |
604 | 608 | | |
605 | 609 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
| 30 | + | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| |||
1175 | 1174 | | |
1176 | 1175 | | |
1177 | 1176 | | |
1178 | | - | |
1179 | | - | |
1180 | | - | |
1181 | | - | |
1182 | | - | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
1183 | 1188 | | |
1184 | 1189 | | |
1185 | 1190 | | |
| |||
1189 | 1194 | | |
1190 | 1195 | | |
1191 | 1196 | | |
1192 | | - | |
1193 | | - | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
1194 | 1205 | | |
1195 | 1206 | | |
1196 | 1207 | | |
| |||
1199 | 1210 | | |
1200 | 1211 | | |
1201 | 1212 | | |
1202 | | - | |
1203 | | - | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
1204 | 1235 | | |
1205 | 1236 | | |
1206 | 1237 | | |
| |||
1228 | 1259 | | |
1229 | 1260 | | |
1230 | 1261 | | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
1231 | 1266 | | |
1232 | 1267 | | |
1233 | 1268 | | |
1234 | 1269 | | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
1235 | 1275 | | |
1236 | | - | |
| 1276 | + | |
1237 | 1277 | | |
1238 | | - | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
1239 | 1287 | | |
1240 | 1288 | | |
1241 | 1289 | | |
| |||
2552 | 2600 | | |
2553 | 2601 | | |
2554 | 2602 | | |
2555 | | - | |
| 2603 | + | |
2556 | 2604 | | |
2557 | 2605 | | |
2558 | 2606 | | |
| |||
3980 | 4028 | | |
3981 | 4029 | | |
3982 | 4030 | | |
3983 | | - | |
| 4031 | + | |
| 4032 | + | |
| 4033 | + | |
| 4034 | + | |
3984 | 4035 | | |
3985 | 4036 | | |
3986 | 4037 | | |
| |||
3991 | 4042 | | |
3992 | 4043 | | |
3993 | 4044 | | |
3994 | | - | |
3995 | 4045 | | |
3996 | | - | |
| 4046 | + | |
| 4047 | + | |
| 4048 | + | |
| 4049 | + | |
3997 | 4050 | | |
3998 | 4051 | | |
3999 | 4052 | | |
| |||
4087 | 4140 | | |
4088 | 4141 | | |
4089 | 4142 | | |
4090 | | - | |
| 4143 | + | |
| 4144 | + | |
| 4145 | + | |
| 4146 | + | |
4091 | 4147 | | |
4092 | 4148 | | |
4093 | 4149 | | |
| |||
4098 | 4154 | | |
4099 | 4155 | | |
4100 | 4156 | | |
4101 | | - | |
4102 | 4157 | | |
4103 | | - | |
| 4158 | + | |
| 4159 | + | |
| 4160 | + | |
| 4161 | + | |
4104 | 4162 | | |
4105 | 4163 | | |
4106 | 4164 | | |
| |||
0 commit comments