Skip to content

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

Draft
ottobolyos wants to merge 1 commit intoTrakHound: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 intoTrakHound:masterfrom
ottobolyos:fix/issue-154

Conversation

@ottobolyos
Copy link
Copy Markdown

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.

Tests

tests/MTConnect.NET-JSON-cppagent-Tests/Streams/JsonConditionsArrayShapeTests.cs pins the wire shape: empty / single-level / multi-level / multi-entry-per-level write cases assert array shape + ordering + per-wrapper key. Round-trip stability through the typed POCO is byte-identical modulo whitespace. Legacy object-keyed read parses correctly. Null write / null read / invalid-token throws. 16/16 pass.

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.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

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)

1 participant