Skip to content

Prototype explicit emit-null vs omit-when-empty policy for optional and nullable fields #102

Done

Description

@clockblocker

Question

What first-class rfl::Nullable<T> wrapper or processor policy cleanly distinguishes "omit key when absent" (std::optional<T>) from "always emit "field": null when empty while accepting omitted/null/value on read and emitting valid Draft 2020-12 nullable JSON Schema"?

Evidence & Context

  • Parent map: Map (Lane 4): Schema & Contract Fidelity
  • solidity Yul AST: YulVariableDeclaration::value and YulAssignment::value required a custom DefaultVal<Nullable<YulExpression>> + Reflector workaround to always serialize "value": null, accept omitted/null/object on input, and emit valid Draft 2020-12 JSON Schema.

Prototype & Measurement Plan

  • Prototype on: showcase/all-lanes — prototype rfl::Nullable<T> (and/or an explicit emit-null processor) covering read, write, and Draft 2020-12 JSON Schema generation.
  • Measure against real Showcase Migration: Validate against solidity Yul AST by deleting the custom DefaultVal<Nullable<...>> + Reflector workaround on YulVariableDeclaration::value / YulAssignment::value and verifying AST round-trips and schema output.
  • Judges & landing: Run Judges (gemini-4-neon + claude-opus-5-5 high via antigravity delegates) on the prototype diff and measurements; if green, hand to coordinator to land on showcase/all-lanes.

Activity

  1. added
    wayfinder:prototype
    on Nov 27, 2026
  2. clockblocker commented on Nov 27, 2026

    @clockblocker
    OwnerAuthor

    Additional Showcase Requirement — Tri-State Field Presence on Read (clockblocker/transmission#1, 6478ae0d0):

    • Source: transmission/libtransmission/rpc-schema.h (lines 75–113, 735–787).
    • JSON-RPC 2.0 requires distinguishing omitted "id" (notification) from explicit "id": null (null request ID). Because std::optional<T> collapses omitted and explicit null into std::nullopt, transmission#1 had to write a ~55-line custom Parser<R, W, RequestId> + DefaultVal<RequestId> workaround.
    • Prototype scope extension: Cover both halves cohesively in this ticket — write-side explicit emit-null vs omit (solidity#3) and read-side tri-state field presence (omitted vs explicit null vs value, transmission#1) — and validate by deleting rpc-schema.h's custom RequestId parser alongside solidity#3's YulVariableDeclaration::value workaround.
  3. clockblocker commented on Nov 27, 2026

    @clockblocker
    OwnerAuthor

    Additional Active Regression Harness Requirement (clockblocker/slang-server#1, bf857f4):

    • Source: slang-server/src/Config.cpp:130-163 (buildPatternExplicit / flagsByFile).
    • rfl::json::read_into currently lacks field-presence / explicit-null tracking, so layered config loading cannot distinguish a field omitted across all layers from one explicitly set to null or its default value — one of the two blockers that prevented adopting #81 (read_into) in Config.cpp.
    • Together with clockblocker/transmission#1 (JSON-RPC 2.0 tri-state "id"), this confirms tri-state presence (omitted vs explicit null vs value) should work cleanly across both read and read_into (as well as write + Draft 2020-12 JSON Schema).
  4. added 3 commits that reference this issue on Nov 27, 2026
  5. clockblocker commented on Nov 27, 2026

    @clockblocker
    OwnerAuthor

    Landed on showcase/all-lanes at 2b1fdb9b (62649db6 + 6280453b + 2b1fdb9b), approved by dual independent Judges (claude-opus-5-5 high + gemini-4-neon high, both APPROVE WITH NITS after resolving all initial blockers and nits).

    Implemented

    1. rfl::Nullable<T> (include/rfl/Nullable.hpp, include/rfl/parsing/ParserNullable.hpp):
      • Always serializes explicitly ("field": null when empty, "field": <value> when present), unlike std::optional<T> which omits empty keys.
      • Accepts omitted key, explicit null, or value on read, preserves base when omitted and overrides with null on explicit null in read_into, and emits Draft 2020-12 nullable JSON Schema (anyOf: [<T>, {"type": "null"}], not required unless NoOptionals).
    2. rfl::TriState<T> + rfl::omitted (include/rfl/TriState.hpp, include/rfl/parsing/ParserTriState.hpp):
      • Distinguishes State::omitted (default-constructed; omitted on write), State::null (std::nullopt; emits "field": null), and State::value across read, read_into (layered config overlay + recursive nested struct overlay), write, and Draft 2020-12 JSON Schema.
      • Strong exception safety in emplace and operator=, conditional explicit(!std::is_convertible_v<U&&, T>), bool optional-like conversion guard, constrained copy/move members for move-only T.
    3. rfl::AddNullFields (include/rfl/AddNullFields.hpp, include/rfl/internal/add_null_fields_v.hpp):
      • Write-side processor emitting "field": null for empty optional/nullable fields without making them mandatory on read, while preserving TriState::omitted and non-nullable empty containers in XML/env.
    4. Full ecosystem wiring: is_required.hpp, is_nullable.hpp, is_empty.hpp, check_default_value.hpp, NamedTupleParser.hpp, Parser_default.hpp, cli/options.hpp, cli/read.hpp, cli/usage.hpp, is_attribute.hpp, and field_aliases.hpp.
    5. Verification: tests/json/test_nullable_and_tristate.cpp covering JSON, read_into layered overlay, Generic, nlohmann, XML, CLI, aliases, wrappers, move-only/non-default-constructible types, and Draft 2020-12 schema — 1,106/1,106 CTests passing, 0 warnings (-Wall -Werror, REFLECTCPP_STRICT_WARNINGS=ON).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wayfinder:prototype

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions