fix(json-cppagent): emit Conditions as cppagent v2 array-of-wrappers (#154)#155
Draft
ottobolyos wants to merge 1 commit intoTrakHound:masterfrom
Draft
fix(json-cppagent): emit Conditions as cppagent v2 array-of-wrappers (#154)#155ottobolyos wants to merge 1 commit intoTrakHound:masterfrom
ottobolyos wants to merge 1 commit intoTrakHound:masterfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #154.
MTConnect.NET-JSON-cppagent'sJsonConditionswas 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 XSDConditionListType<xs:sequence>of<xs:choice>semantics.This PR adds a
JsonConverter<JsonConditions>that:{LevelName: JsonCondition}wrappers, in the same enumeration order the existingJsonConditions.Observationsgetter uses.Tests
tests/MTConnect.NET-JSON-cppagent-Tests/Streams/JsonConditionsArrayShapeTests.cspins 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
https://schemas.mtconnect.org/schemas/MTConnectStreams_2.7.xsd—ConditionListType.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.