fix(json-cppagent): emit numeric Sample values as JSON numbers#143
Draft
ottobolyos wants to merge 17 commits intoTrakHound:masterfrom
Draft
fix(json-cppagent): emit numeric Sample values as JSON numbers#143ottobolyos wants to merge 17 commits intoTrakHound:masterfrom
ottobolyos wants to merge 17 commits intoTrakHound:masterfrom
Conversation
3025b22 to
ef14a82
Compare
0688b61 to
2253cf5
Compare
The docs/testing/issue-129/ subtree carried phase-by-phase campaign writeups that referenced internal tooling (CONVENTIONS rule-book, internal section numbers, extra-files.user/ paths, internal tracker terminology). Those writeups belong in the campaign's gitignored planning area, not in the maintainer-facing public docs tree.
Addresses follow-up findings on the JsonSampleValueConverter and the JsonSampleValue carrier surfaced after the initial issue-129 fix: - JsonSampleValueConverter: gate WriteNumberValue on double.IsFinite so NaN/Infinity round-trip as JSON string tokens instead of crashing the Utf8JsonWriter. - JsonSampleValueConverter: empty/whitespace-only string values emit a JSON null token, keeping the wire shape consistent with "no value supplied". - JsonSampleValueConverter: short-circuit on a space character before double.TryParse so ThreeSpaceSampleValueType payloads stay on the cheap path. - JsonSampleValueConverter: replace string.Format fallback with Convert.ToString(value, InvariantCulture) so the contract is explicit for non-string non-numeric carriers. - JsonSampleValueConverter.Read: throw JsonException on unsupported token kinds (boolean / array / object) so feed corruption is visible to callers instead of being silently dropped. - JsonSampleValue.ToObservation: null-guard ResetTriggered and Statistic round-trips so omitting the JSON property no longer stamps the observation with a stray default-enum value (mirrors the JsonDataItem.ToDataItem path). - SampleValueWireFormatE2ETests: re-word XML doc to drop references to internal planning conventions. Tests: - New JsonSampleValueConverterEdgeCaseTests covers each behavioral finding (non-finite numbers, empty/whitespace null, ThreeSpace short circuit, invariant-culture fallback, Read default-branch throw). - New JsonSampleValueToObservationTests pins the null-guard behavior on the carrier's ToObservation path. - New TestHelpers/RepoRootLocator extracts the bin-folder walk-up helper so source-surface guards share one implementation. - SampleValueWriteStringValueGuardTests now consumes the shared RepoRootLocator instead of carrying its own copy of the helper. - JsonSampleValueNumericTokenTests removes the "returns null for unsupported token" case (now covered by the throws-JsonException pin in JsonSampleValueConverterEdgeCaseTests).
`double.IsFinite` is a .NET Core 2.1 / .NET 5+ / netstandard 2.1 API.
MTConnect.NET-JSON-cppagent multi-targets net47 / net48 / netstandard2.0
in Release where the method does not exist; the Release build failed
with CS0117 ('double' does not contain a definition for 'IsFinite')
and CS0165 (the cascading 'parsed' unassigned-local error).
Replace with the equivalent guard `!double.IsNaN(parsed) &&
!double.IsInfinity(parsed)` which is available on every supported TFM.
The behaviour is identical: both reject NaN, +Infinity, and -Infinity
and accept every finite double.
Surfaced via `dotnet pack -c Release` from the integration branch.
The five section headers in JsonSampleValueConverterEdgeCaseTests carried internal audit-finding codes; rewrite each header so the comment is a self-contained one-line description of the contract being pinned. Also remove the same code reference from the trailing note in JsonSampleValueNumericTokenTests.
1400e96 to
fe1bb6d
Compare
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
Fixes #129 — numeric Sample values were emitted as JSON string tokens under the
JSON-cppagentformatter, breaking parity with the cppagent reference implementation and the XSDFloatSampleValueTypeunion (xs:float|"UNAVAILABLE")."UNAVAILABLE"sentinel still serializes as a string token.JsonConverteron the Sample-valueobjectproperty branches on the runtime type: numeric primitives go throughWriteNumberValue; theUNAVAILABLEsentinel and any non-numeric fallback go throughWriteStringValue.double.IsFinitewith a cross-TFM-portable finite-value check so the converter compiles onnetstandard2.0/net48.MTConnect.NET-JSON-cppagent-Testscovers numeric, sentinel, edge-case, and three-space scenarios plus a guard that scans the cppagent library for unconditionalWriteStringValueagainst Sample-value writers.IObservationto JSON path under the cppagent formatter.