Skip to content

fix(json-cppagent): drop JsonConditionsConverter; list-derived shape - #208

Draft
ottobolyos wants to merge 2 commits into
TrakHound:masterfrom
ottobolyos:fix/jsonconditions-structural-rewrite
Draft

fix(json-cppagent): drop JsonConditionsConverter; list-derived shape#208
ottobolyos wants to merge 2 commits into
TrakHound:masterfrom
ottobolyos:fix/jsonconditions-structural-rewrite

Conversation

@ottobolyos

Copy link
Copy Markdown
Contributor

Summary

Closes the ~200-line hand-written JsonConditionsConverter and rewrites JsonConditions as List<JsonConditionWrapper>-derived so the type shape IS the cppagent JSON v2 wire shape. System.Text.Json's default serialiser handles both directions with no custom converter — round-trip is symmetric by construction, no reader-state edge cases to defend against, and the wire is byte-compatible with the pre-refactor output when the emission pipeline uses the same sparse-serialisation options.

Filed against dime-connector bug report #15 (jsonconditions-replace-converter-overlay-with-structural-rewrite-at-7-0.md); this is the mtc.net upstream side of that follow-up to #12 (v1 → v2 wire-shape fix). Targeted at the 7.0 major-bump window so the API-break window is already open.

Change

  • New JsonConditionWrapper (libraries/MTConnect.NET-JSON-cppagent/Streams/JsonConditionWrapper.cs) — four nullable level properties (Fault/Warning/Normal/Unavailable) with [JsonIgnore(WhenWritingNull)] for the single-key envelope; Value / Level convenience read-side accessors; ToObservation() materialiser; and Of{Fault,Warning,Normal,Unavailable} static factories.
  • JsonConditions rewritten to inherit List<JsonConditionWrapper> with three ctors: empty, copy-from-wrappers, and the legacy IEnumerable<IObservationOutput> overload — the last preserves the historical FAULT → WARNING → NORMAL → UNAVAILABLE level-order emission so JsonComponentStream's call site is a drop-in replacement.
  • JsonConditionsConverter deleted — the entire class.

Behavioural changes (intentional at 7.0)

  • Legacy MTConnect JSON v1 object-keyed READ compat is dropped. The default List<T> deserialiser only reads arrays; the pre-7.0 fallback to {"Fault":[…], "Warning":[…]} envelope is removed. #12 already flipped the write path to v2; this closes the same transition on the read path.
  • Mixed-level wire interleaving is no longer re-bucketed by level on write. Insertion order is preserved end-to-end. Producers that want the historical level-order can either use the IEnumerable<IObservationOutput> ctor (unchanged) or sort explicitly before construction.
  • Strict malformed-wrapper rejection with named JsonException messages is dropped. Default S.T.J tolerance applies; malformed input produces default S.T.J errors instead of custom prose.

Test plan

  • dotnet test tests/MTConnect.NET-JSON-cppagent-Tests/ --filter "FullyQualifiedName~JsonCondition" — 47/47 GREEN (bluefin net8.0 verified 56c61e9a).
  • JsonConditionWrapperTests (24 tests) — factory contracts, Value/Level precedence (Fault > Warning > Normal > Unavailable), ToObservation materialisation at each level + empty, wire envelope serialisation, per-envelope deserialisation.
  • JsonConditionsArrayShapeTests (23 tests) — three ctors (default, copy, observation-sequence with null / empty / level-order / null-entry-skip), Observations accessor (empty / insertion-order / skip-empty-wrappers), wire shape (empty array / single wrapper / insertion order preserved / observation-ctor level order / round-trip byte-identical / root null).
  • Full MTConnect.NET-JSON-cppagent-Tests.csproj suite — verified GREEN on bluefin.
  • Cascades cleanly through integration/all-fixes re-build.

Commits (single):

  1. fix(json-cppagent): replace JsonConditionsConverter with structural rewrite

https://claude.ai/code/session_015FLSuNX8hZPFiTGtE8GYqH

@ottobolyos
ottobolyos force-pushed the fix/jsonconditions-structural-rewrite branch from 5af1437 to e26e9ff Compare July 22, 2026 19:09
@ottobolyos ottobolyos changed the title fix(json-cppagent): drop JsonConditionsConverter for structural rewrite fix(json-cppagent): drop JsonConditionsConverter; list-derived shape Jul 22, 2026
@ottobolyos
ottobolyos force-pushed the fix/jsonconditions-structural-rewrite branch from e26e9ff to 4d19791 Compare July 22, 2026 19:17
…ers surface (RED)

Adds JsonConditionWrapperTests and rewrites JsonConditionsArrayShapeTests
to pin the cppagent JSON v2 array-of-single-key-wrappers wire shape via
the new JsonConditionWrapper + list-derived JsonConditions surface that
the following fix commit introduces.

New coverage in JsonConditionWrapperTests (24 tests):

* Four Of{Fault,Warning,Normal,Unavailable} factory contracts
  (each populates exactly one level, others null).
* Value accessor: null on empty, correct return for each of the four
  single-populated levels, and Fault > Warning > Normal > Unavailable
  precedence on multi-populated wrappers.
* Level accessor: null on empty, correct wire-property-name return
  for each of the four single-populated levels.
* ToObservation materializer: null on empty, correct level enum
  for each of the four single-populated levels.
* Wire envelope serialization: single-key output under sparse
  options, convenience-accessor suppression, empty-wrapper -> {},
  multi-populated documentation.
* Per-envelope deserialization: each of the four single-key inputs
  populates the matching property and leaves the other three null.

Rewritten JsonConditionsArrayShapeTests (23 tests):

* Three ctors covered: default (empty), copy-from-wrappers (insertion
  order preserved), and IEnumerable<IObservationOutput> (null-arg /
  empty / level-order emission / null-entry-skip).
* Observations computed accessor: empty container, materialization
  in insertion order across all four levels, empty-wrapper skip.
* Wire shape: [] on empty, single Normal wrapper, insertion order
  preserved across mixed levels, observation-ctor Fault-Warning-
  Normal-Unavailable level order, mixed-level array deserialization
  populates the correct wrapper property, round-trip byte-identical,
  root null <-> "null".

This commit is compile-error RED per CONVENTIONS §1.0d-vicies-semel:
the tests reference JsonConditionWrapper, the list-shape JsonConditions,
and the AmE parameter names / XML-doc verbs that all land in the
following fix commit.

Claude-Session: https://claude.ai/code/session_015FLSuNX8hZPFiTGtE8GYqH
Deletes JsonConditionsConverter (~200 lines) and rewrites
JsonConditions as List<JsonConditionWrapper>-derived so the type
shape IS the wire shape. System.Text.Json's default serializer
handles both directions with no custom converter code.

New shape:

* JsonConditions : List<JsonConditionWrapper> — three ctors:
  parameterless, copy-from-wrappers, and IEnumerable<IObservationOutput>
  which preserves the historical Fault -> Warning -> Normal ->
  Unavailable level-order emission for byte-compatible wire output
  against the pre-refactor converter under sparse serialization
  options.
* JsonConditionWrapper — four nullable level properties with
  [JsonIgnore(WhenWritingNull)] for the single-key envelope,
  Value / Level convenience read-side accessors, ToObservation
  materializer, and OfFault / OfWarning / OfNormal / OfUnavailable
  factories.

Deletions:

* JsonConditionsConverter.cs — the entire class.
* [JsonConverter(typeof(JsonConditionsConverter))] attribute on
  JsonConditions.

Behavioral changes (intentional at 7.0 major-bump window):

* Legacy MTConnect JSON v1 object-keyed READ compat is dropped.
  The default List<T> deserializer only reads arrays; the pre-7.0
  fallback to {"Fault":[...], "Warning":[...]} envelope is removed.
* Mixed-level wire interleaving is no longer re-bucketed by level
  on write — insertion order is preserved end-to-end. Producers
  wanting the historical grouping can use the IEnumerable<
  IObservationOutput> ctor or sort explicitly.
* Strict malformed-wrapper rejection with named JsonException
  messages is dropped; default S.T.J tolerance applies.

Turns the RED tests from the preceding commit GREEN:
  47/47 on JsonCondition* filter; 391/391 on the full
  MTConnect.NET-JSON-cppagent-Tests suite (bluefin net8.0).

Closes dime-connector bug report TrakHound#15 on the mtc.net upstream side.

Claude-Session: https://claude.ai/code/session_015FLSuNX8hZPFiTGtE8GYqH
@ottobolyos
ottobolyos force-pushed the fix/jsonconditions-structural-rewrite branch from 4d19791 to 74b8749 Compare July 23, 2026 18:10
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.

1 participant