This is an archive of the discontinued LLVM Phabricator instance.

[JSON] Add ObjectMapper::mapOptional to validate optional data.
ClosedPublic

Authored by sammccall on Oct 9 2020, 6:34 AM.

Details

Summary

Currently the idiom for mapping optional fields is:

ObjectMapper O(Val, P);
if (!O.map("required1", Out.R1) || !O.map("required2", Out.R2))
  return false;
O.map("optional1", Out.O1); // ignore result
return true;

If optional1 is present but malformed, then we won't detect/report
that error. We may even leave Out in an incomplete state while returning true.
Instead, we'd often prefer to ignore optional1 if it is absent, but otherwise
behave just like map().

Diff Detail

Event Timeline

sammccall created this revision.Oct 9 2020, 6:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 9 2020, 6:34 AM
sammccall requested review of this revision.Oct 9 2020, 6:34 AM
hokein accepted this revision.Oct 12 2020, 1:56 AM
This revision is now accepted and ready to land.Oct 12 2020, 1:56 AM