Skip to content

DEMO: Serialize UOPD with a collection DTO and attributed ordinates - #152

Open
Brennan1994 wants to merge 3 commits into
mainfrom
InvestigateExistingJson
Open

Brennan1994 wants to merge 3 commits into
mainfrom
InvestigateExistingJson

Conversation

@Brennan1994

@Brennan1994 Brennan1994 commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

DEMO of JSON round trips for UncertainOrderedPairedData (UOPD) while retaining its IList interface. Default System.Text.Json collection serialization omits UOPD's ordering and validation settings, so a small converter uses a collection DTO to write an object containing those settings and an Ordinates array.

Serialization approach

  • Attach UncertainOrderedPairedDataConverter to UOPD through JsonConverter, allowing normal JsonSerializer calls without converter registration.
  • Use one private sealed UncertainOrderedPairedDataDto for the collection's object shape. It contains the validation settings and a List; there is no ordinate DTO.
  • Put attributes directly on UncertainOrdinate.X and Y. Reuse the existing UnivariateDistributionConverter for Y to preserve distribution types and parameters. JsonConverters.cs is unchanged relative to main; its existing type-and-parameters limitations still apply.
  • Persist StrictX, StrictY, OrderX, OrderY, Distribution, AllowDifferentDistributionTypes, and ValidationTailProbability alongside the ordinates. Neither collection nor ordinate IsValid is persisted.
  • Recompute ordinate validity directly in IJsonOnDeserialized and reject null Y distributions. JsonRequired rejects missing properties; JsonIgnore(Never) keeps required default-valued properties when caller options omit defaults. Number-handling attributes support non-finite X values and the default NaN tail probability.

Reconstruction and allocation choices

  • Serialization gives the DTO the existing backing list through an internal accessor, avoiding a temporary ordinate array or list copy.
  • Deserialization hands the serializer-created list to an internal UOPD constructor. The constructor takes ownership, applies the settings, and validates the completed collection once. It does not allocate and populate a second ordinate list.
  • Keep the collection DTO as a sealed class: a record class would still allocate a DTO object and would add generated equality/copying members that this path does not use.
  • Reject null ordinate collections and invalid tail probabilities; invalid tail probabilities retain their original exception as the inner exception.
  • Require the object format, since the earlier bare array omitted the settings needed to reconstruct validation. The public collection API and numerical validation rules remain intact.
  • Include a justified pynumerics coverage exclusion for the public serialization converter.

Validation

  • Release build: zero errors and warnings on net10.0 and net481.
  • Full .NET tests excluding LiveServiceIntegration: 4,099 passed on net10.0 and 4,082 passed on net481; zero failures or skipped tests.
  • Coverage includes ordering and strictness, mixed distributions, tail validation, list reuse, standalone ordinate round trips, recomputed validity, null/empty collections, missing or invalid input, and caller serializer options.
  • Python tests were not run at the user's request.

@Brennan1994 Brennan1994 changed the title DEMO: Serialize UncertainOrderedPairedData using JSON converters and DTOs DEMO: Serialize UOPD with a collection DTO and attributed ordinates Dec 3, 2026
@Brennan1994

Copy link
Copy Markdown
Collaborator Author

This is my preference right now. Then build off this with consequences. Use true-er attribute based serialization in consequences where possbile - fall back to a converter and DTO like this where it's not.

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