std.json: stringify enum literals (#16742)
This commit is contained in:
@@ -181,6 +181,7 @@ pub fn writeStreamArbitraryDepth(
|
||||
/// * 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`.
|
||||
/// * Zig `enum` -> JSON string naming the active tag.
|
||||
/// * 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`.
|
||||
/// * Zig untyped enum literal -> JSON string naming the active tag.
|
||||
/// * Zig error -> JSON string naming the error.
|
||||
/// * Zig `*T` -> the rendering of `T`. Note there is no guard against circular-reference infinite recursion.
|
||||
///
|
||||
@@ -449,7 +450,7 @@ pub fn WriteStream(
|
||||
return try self.write(null);
|
||||
}
|
||||
},
|
||||
.Enum => {
|
||||
.Enum, .EnumLiteral => {
|
||||
if (comptime std.meta.trait.hasFn("jsonStringify")(T)) {
|
||||
return value.jsonStringify(self);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user