Skip to content

Provide optional-field accessor helpers in score::json (GetAttribute usability) #487

Description

@gordon9901

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<T>(obj, key) does not accept a raw const Object& (only reference_wrapper<const Object> or Result<...>), forcing callers to wrap with std::cref() or fall back to manual find -> second.As<T>().
  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 (eclipse-score/time#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)

  • An issue is filed against eclipse-score/baselibs describing the gap, referencing this ticket.
  • Either the API is extended (e.g. accept const Object&, or add a helper that distinguishes missing-key from type-error), or the intended usage is documented so downstream projects don't have to reinvent these wrappers.

How

No response

Metadata

Metadata

Assignees

Labels

comp-jsonRelated to score/json component

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions