| ... | ... | @@ -483,6 +483,7 @@ pub fn WriteStream( |
| 483 | 483 | /// * If the union declares a method `pub fn jsonStringify(self: *@This(), jw: anytype) !void`, it is called to do the serialization instead of the default behavior. The given `jw` is a pointer to this `WriteStream`. |
| 484 | 484 | /// * Zig `enum` -> JSON string naming the active tag. |
| 485 | 485 | /// * If the enum declares a method `pub fn jsonStringify(self: *@This(), jw: anytype) !void`, it is called to do the serialization instead of the default behavior. The given `jw` is a pointer to this `WriteStream`. |
| 486 | /// * If the enum is non-exhaustive, unnamed values are rendered as integers. |
| 486 | 487 | /// * Zig untyped enum literal -> JSON string naming the active tag. |
| 487 | 488 | /// * Zig error -> JSON string naming the error. |
| 488 | 489 | /// * Zig `*T` -> the rendering of `T`. Note there is no guard against circular-reference infinite recursion. |
| ... | ... | @@ -540,11 +541,24 @@ pub fn WriteStream( |
| 540 | 541 | return try self.write(null); |
| 541 | 542 | } |
| 542 | 543 | }, |
| 543 | | .@"enum", .enum_literal => { |
| 544 | .@"enum" => |enum_info| { |
| 544 | 545 | if (std.meta.hasFn(T, "jsonStringify")) { |
| 545 | 546 | return value.jsonStringify(self); |
| 546 | 547 | } |
| 547 | 548 | |
| 549 | if (!enum_info.is_exhaustive) { |
| 550 | inline for (enum_info.fields) |field| { |
| 551 | if (value == @field(T, field.name)) { |
| 552 | break; |
| 553 | } |
| 554 | } else { |
| 555 | return self.write(@intFromEnum(value)); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | return self.stringValue(@tagName(value)); |
| 560 | }, |
| 561 | .enum_literal => { |
| 548 | 562 | return self.stringValue(@tagName(value)); |
| 549 | 563 | }, |
| 550 | 564 | .@"union" => { |