Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] What if we always emitted optional fields? #6133

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Omit @nextlink, rather than emitting as null
  • Loading branch information
eddyashton committed Jun 18, 2024
commit 939af870c21470036c46a2626a5d35224171e45b
7 changes: 7 additions & 0 deletions samples/apps/logging/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,13 @@ namespace loggingapp

// Construct the HTTP response
nlohmann::json j_response = response;

// Prefer missing field to null, in this case
if (!response.next_link.has_value())
{
j_response.erase("@nextLink");
}

ctx.rpc_ctx->set_response_status(HTTP_STATUS_OK);
ctx.rpc_ctx->set_response_header(
http::headers::CONTENT_TYPE, http::headervalues::contenttype::JSON);
Expand Down