Skip to content

DEMO: True Attribute Based Serialization for UncertainPairedData - #154

Open
Brennan1994 wants to merge 3 commits into
mainfrom
AttributeOnlyUncertainPairedDataJson
Open

Brennan1994 wants to merge 3 commits into
mainfrom
AttributeOnlyUncertainPairedDataJson

Conversation

@Brennan1994

Copy link
Copy Markdown
Collaborator

This DEMO shows the simpler JSON serialization available when UncertainOrderedPairedData no longer implements IList or its inherited collection interfaces. It intentionally breaks the collection API and is an exploration, not a production-compatible replacement.

Serialization approach

  • Put System.Text.Json attributes directly on UncertainOrderedPairedData and UncertainOrdinate. No DTOs, manual JSON reader/writer, or UOPD converter are needed.
  • Persist StrictX, StrictY, OrderX, OrderY, Distribution, AllowDifferentDistributionTypes, ValidationTailProbability, and Ordinates. The JSON constructor retains the deserialized ordinate list directly and validates the completed collection once when its tail setting is valid.
  • Reuse the existing UnivariateDistributionConverter on each ordinate's Y field to preserve its distribution type and parameters. JsonConverters.cs is unchanged relative to main.
  • Recompute ordinate validity directly in IJsonOnDeserialized and reject null Y distributions. Neither ordinate nor collection IsValid is serialized.
  • Preserve required zero/false values under caller options that omit defaults, support named non-finite numbers such as the default NaN tail probability, and leave JSON object property order unspecified.
  • Treat an out-of-range tail probability such as 0.6 as invalid input data that can still deserialize: retain the value and set collection IsValid to false. Existing property-setter and pairwise-validation checks remain in place.

API tradeoffs

Removing IList/IEnumerable lets System.Text.Json treat UOPD as an object. Interface-based consumers and LINQ extension calls must instead use the exposed Ordinates list or existing collection members. Update the affected TabularFunction call and Count assertions accordingly. Pattern-based foreach remains available through GetEnumerator.

Ordinates exposes the mutable backing list; direct edits bypass UOPD's validation and collection notifications. This demo deliberately prioritizes a simple attribute-based design over API stability and backward compatibility. It has no performance benchmark claims.

Validation

  • dotnet build -c Release: passed, zero warnings and errors.
  • dotnet test -c Release --no-build --filter "TestCategory!=LiveServiceIntegration": passed; 4,116 tests on net10.0 and 4,099 on net481, zero failures or skips.
  • Coverage includes ordering and validation settings, mixed distributions, standalone ordinate validity, null distributions, missing fields, reordered properties, caller serializer options, non-finite numbers, and invalid tail probabilities that can be loaded and corrected.
  • Python testing skipped at the user's request. Added a coverage-registry exclusion for the JSON Ordinates view.

@Brennan1994

Copy link
Copy Markdown
Collaborator Author

This demonstrates the attribute-based serialization approach we initially hoped to use. However, because UncertainOrderedPairedData implements IList, System.Text.Json treats it as a collection and serializes its elements as an array, omitting its additional properties. Property attributes alone cannot override that behavior. To preserve both the collection interface and those properties when serializing this class directly, we use a custom converter in the other approach. This branch removes the collection interface as a proof of concept, allowing ordinary attribute-based object serialization.

@Brennan1994 Brennan1994 changed the title DEMO: Serialize uncertain paired data with attributes and no IList DEMO: True Attribute Based Serialization for UncertainPairedData Dec 3, 2026

This branch has not been deployed

No deployments
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