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

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 06:34:33 PDT 2020


sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
sammccall requested review of this revision.

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().


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89128

Files:
  llvm/include/llvm/Support/JSON.h
  llvm/unittests/Support/JSONTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89128.297222.patch
Type: text/x-patch
Size: 3690 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201009/c1f4b447/attachment.bin>


More information about the llvm-commits mailing list