Skip to content

fix(json-cppagent): emit Conditions as cppagent v2 array-of-wrappers (#154)#155

Draft
ottobolyos wants to merge 1 commit into
TrakHound:masterfrom
ottobolyos:fix/issue-154
Draft

fix(json-cppagent): emit Conditions as cppagent v2 array-of-wrappers (#154)#155
ottobolyos wants to merge 1 commit into
TrakHound:masterfrom
ottobolyos:fix/issue-154

Conversation

@ottobolyos
Copy link
Copy Markdown
Contributor

@ottobolyos ottobolyos commented Apr 30, 2026

Summary

Closes #154.

MTConnect.NET-JSON-cppagent's JsonConditions was serialising Conditions as the legacy MTConnect JSON v1 object-keyed shape ({Fault: [...], Warning: [...], ...}). Strict cppagent JSON v2 consumers reject that shape — they expect an array of single-key wrapper objects ([{Normal: {...}}, {Warning: {...}}, ...]) per the cppagent reference and the XSD ConditionListType <xs:sequence> of <xs:choice> semantics.

This PR adds a JsonConverter<JsonConditions> that:

  • On Write: projects the four typed properties (Fault / Warning / Normal / Unavailable) into an array of {LevelName: JsonCondition} wrappers, in the same enumeration order the existing JsonConditions.Observations getter uses.
  • On Read: accepts both the new array shape (cppagent v2) and the legacy object-keyed shape (back-compat), so older agents / consumers continue to interop.

Spec authority

  • XSD: https://schemas.mtconnect.org/schemas/MTConnectStreams_2.7.xsdConditionListType.
  • Prose: MTConnect Standard Part 2 §13 "Condition".
  • cppagent reference (v2.7.0.7): printer/json_printer.cpp::print_condition.

Backward compatibility

The Read path accepts both shapes; existing producers / consumers that emitted or expected the v1 object-keyed shape continue to round-trip through the typed POCO without change. The Write path always emits the v2 array shape — that's the wire-format-correctness fix.

JsonConditions previously serialised as the v1 object-keyed shape
({Fault: [...], Warning: [...], Normal: [...], Unavailable: [...]}).
Strict cppagent JSON v2 consumers reject that shape — they expect an
array of single-key wrapper objects ([{Normal: {...}}, {Warning: {...}},
...]) per the cppagent reference and the XSD ConditionListType
<xs:sequence> of <xs:choice> semantics.

Add a JsonConverter<JsonConditions> on the class that, on Write,
projects the four typed properties (Fault / Warning / Normal /
Unavailable) into an array of single-key wrappers in the same order
the existing JsonConditions.Observations getter uses. On Read, it
accepts both the new array shape and the legacy object-keyed shape
so older agents and consumers continue to interop.

Spec authority:
  XSD: https://schemas.mtconnect.org/schemas/MTConnectStreams_2.7.xsd
       (ConditionListType complex type)
  Prose: MTConnect Standard Part 2 section 13 "Condition"
  cppagent reference (v2.7.0.7): printer/json_printer.cpp::print_condition

Closes TrakHound#154.
@ottobolyos ottobolyos marked this pull request as ready for review May 13, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

JSON-cppagent-mqtt formatter emits Condition in legacy v1 object shape (not cppagent v2 array of wrappers)

2 participants