Serialization
Status & scope
- Module:
lens/serialization.py - Milestone: Phase 2 (complete)
Purpose
Convert frozen dataclasses to/from JSON-safe dicts. Required for REST transport, evidence block storage, and Beacon rendering.
Public API
to_dict(obj) → dict
- Frozen dataclass → JSON-safe dict. Handles nested dataclasses, tuples, datetimes.
to_json(obj) → str
- Frozen dataclass → JSON string.
from_dict(data, cls) → frozen dataclass
- Dict → frozen dataclass. Type-safe reconstruction.
File Layout
lens/
serialization.py ← to_dict, to_json, from_dict
Integration Points
- REST: LensResult → JSON → Beacon via REST proxy
- Evidence: EvidenceBlock → JSON for storage/sync
- Beacon: from_dict reconstructs typed objects from JSON responses
DO NOT
- Use pickle for cross-process serialization — JSON only for interop
- Lose type information — from_dict must reconstruct the correct dataclass
Depends on: component.prism.evidence-model, component.prism.universal-lens-parser
Required by: component.prism.cost-lens-governance