sanitizeXrayJson function

dynamic sanitizeXrayJson(
  1. dynamic params, {
  2. bool preserveStructure = false,
  3. void onChange(
    1. XrayJsonChange
    )?,
})

Normalizes legacy fields while optionally retaining raw JSON structure.

Typed generators omit absent values by default. Raw configurations must keep explicit nulls and empty containers because Core can distinguish them from omitted fields. Unknown settings and dictionary keys remain caller data.

With preserveStructure true, known compatibility edits are limited to their schema owners: transport aliases and unsupported TLS verification overrides. onChange reports those edits in this mode without exposing private values. With false, typed-generator cleanup also removes null values and empty maps or lists. The result is copied recursively; the input is not modified. Conflicting aliases in inspected full-profile fields throw ArgumentError.

Implementation

dynamic sanitizeXrayJson(
  dynamic params, {
  bool preserveStructure = false,
  void Function(XrayJsonChange)? onChange,
}) {
  final sanitized = _sanitizeXrayJson(
    params,
    preserveStructure: preserveStructure,
    root: true,
  );
  if (preserveStructure && sanitized is JsonMap) {
    _normalizeRawStreamFields(sanitized, onChange);
  }
  return sanitized;
}