From 9c66dd4deb914cd2857f15efe03c9a5356198ba2 Mon Sep 17 00:00:00 2001 From: Ed Yu Date: Tue, 20 Jun 2023 10:21:48 -0700 Subject: [PATCH] Update to new json parser api changes --- examples/endpoint/endpoint.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/endpoint/endpoint.zig b/examples/endpoint/endpoint.zig index 9ee54da..ac4b408 100644 --- a/examples/endpoint/endpoint.zig +++ b/examples/endpoint/endpoint.zig @@ -82,10 +82,10 @@ fn listUsers(self: *Self, r: zap.SimpleRequest) void { fn postUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void { const self = @fieldParentPtr(Self, "endpoint", e); if (r.body) |body| { - var maybe_user: ?User = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null; + var maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null; if (maybe_user) |u| { - defer std.json.parseFree(User, self.alloc, u); - if (self.users.addByName(u.first_name, u.last_name)) |id| { + defer u.deinit(); + if (self.users.addByName(u.value.first_name, u.value.last_name)) |id| { var jsonbuf: [128]u8 = undefined; if (zap.stringifyBuf(&jsonbuf, .{ .status = "OK", .id = id }, .{})) |json| { r.sendJson(json) catch return; @@ -104,11 +104,11 @@ fn putUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void { if (self.userIdFromPath(path)) |id| { if (self.users.get(id)) |_| { if (r.body) |body| { - var maybe_user: ?User = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null; + var maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null; if (maybe_user) |u| { - defer std.json.parseFree(User, self.alloc, u); + defer u.deinit(); var jsonbuf: [128]u8 = undefined; - if (self.users.update(id, u.first_name, u.last_name)) { + if (self.users.update(id, u.value.first_name, u.value.last_name)) { if (zap.stringifyBuf(&jsonbuf, .{ .status = "OK", .id = id }, .{})) |json| { r.sendJson(json) catch return; }