Skip to main content

Module serialization

Module serialization 

Source
Expand description

Format-agnostic contract input and output: JSON and XML.

XML is treated as an alternative syntax for the same data model, not as a second schema. Documents are transcoded to serde_json::Value and then deserialized with the existing serde derives, so both formats share one definition, one set of defaults and one set of validation rules — and a new product supports both the moment it is added.

(Deriving XML directly is not an option here: the data model relies on #[serde(flatten)], internally tagged enums and untagged enums, none of which XML serde implementations support.)

§XML conventions

  • Elements are object fields. <strike_price>100</strike_price> becomes "strike_price": 100.
  • Attributes are object fields too, which reads naturally for the tag of a tagged enum: <discount_curve type="flat"> is the same as "discount_curve": { "type": "flat", ... }.
  • <item> children make an array. <tenors><item>0.5</item> <item>1.0</item></tenors> becomes "tenors": [0.5, 1.0], and a single <item> still yields a one-element array. Repeated non-item siblings also collapse into an array.
  • Scalars are inferred: true/false become booleans, anything parsing as a number becomes a number, an empty element becomes null, everything else stays a string (so 2027-07-17 and C are safe).

Enums§

Format

Constants§

ARRAY_ITEM
Element name that marks array members in XML.

Functions§

parse
Parse a document into any deserializable type, in either format.
parse_value
Parse a document in either format into a Value.
render_results
Render a list of contract results in the requested format.
render_value
Render a single value in the requested format.
strip_nulls
Drop null object fields recursively.