From f5663fd84dc446bff5321c877a0531eefa694c17 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Mon, 26 Aug 2024 16:01:21 -0700 Subject: [PATCH] allow serializeMap to work with optionals --- codegen/src/json.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/codegen/src/json.zig b/codegen/src/json.zig index c9ff0ea..f9bfcf8 100644 --- a/codegen/src/json.zig +++ b/codegen/src/json.zig @@ -2,6 +2,16 @@ const std = @import("std"); // options is a json.Options, but since we're using our hacked json.zig we don't want to // specifically call this out pub fn serializeMap(map: anytype, key: []const u8, options: anytype, out_stream: anytype) !bool { + if (@typeInfo(@TypeOf(map)) == .Optional) { + if (map == null) + return true + else + return serializeMapInternal(map.?, key, options, out_stream); + } + return serializeMapInternal(map, key, options, out_stream); +} + +fn serializeMapInternal(map: anytype, key: []const u8, options: anytype, out_stream: anytype) !bool { if (map.len == 0) return true; // TODO: Map might be [][]struct{key, value} rather than []struct{key, value} var child_options = options;