eclipse-score / eclipse-score/baselibs
Provide optional-field accessor helpers in score::json (GetAttribute usability)
- Dominant language
- C++
- Stars
- 26
- Forks
- 85
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 47
Description
### What
When parsing JSON configuration with `score::json`, consumers cannot cleanly express the common pattern "use the default if the key is missing, fail fast if the key exists but has the wrong type", because:
1. `GetAttribute(obj, key)` does not accept a raw `const Object&` (only `reference_wrapper` or `Result<...>`), forcing callers to wrap with `std::cref()` or fall back to manual `find -> second.As()`.
2. `Result::value_or(default)` swallows type errors together with "key not found", so a mistyped field silently falls back to the default instead of producing a clear error.
While implementing the TimeSlave JSON config parser (https://github.com/eclipse-score/time/pull/158) I had to duplicate the same ~10-line helper wrapper. Other components parsing JSON configs will likely hit the same issue.
### Acceptance Criteria (DoD)
The score::json documentation (README or header docs) is updated to include:
An example showing GetAttribute(std::cref(obj), key) as the standard way to access object fields, clarifying that std::cref/std::ref is the intended calling convention.
An example of the "default on missing key, fail fast on type error" pattern, demonstrating how to distinguish Error::kKeyNotFound from other errors without using value_or.
### How
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.