Skip to main content

Crate helios_serde

Crate helios_serde 

Source
Expand description

§Helios FHIR Server Serialization Module

This crate provides version-agnostic JSON and XML serialization for FHIR resources.

§Features

  • JSON Support: Thin wrappers around serde_json that leverage the existing FhirSerde derive macro for correct FHIR JSON representation. Always available.
  • XML Support: Custom serde::Serializer and serde::Deserializer implementations that stream directly to/from FHIR XML format without materializing JSON intermediates. Requires the xml feature flag: helios-serde = { features = ["xml"] }.
  • Version Agnostic: Works with all FHIR versions (R4, R4B, R5, R6) through the Element<V, E> infrastructure.

§Architecture

The crate uses a streaming approach for maximum performance:

  • JSON Layer: Direct delegation to serde_json functions
  • XML Layer: Custom Serializer/Deserializer trait implementations that:
    • Receive serialize/deserialize calls as the resource is traversed
    • Buffer minimally (only what’s needed for FHIR pattern detection)
    • Write/read quick-xml events directly

§FHIR JSON ↔ XML Mapping

The XML implementation handles FHIR’s unique serialization patterns:

JSON PatternXML Pattern
{"active": true}<active value="true"/>
{"birthDate": "1974-12-25", "_birthDate": {"id": "123"}}<birthDate id="123" value="1974-12-25"/>
{"given": ["John", "Doe"]}<given value="John"/><given value="Doe"/>
{"given": ["A", null], "_given": [null, {"id": "123"}]}<given value="A"/><given id="123"/>

§Examples

§JSON Serialization

use helios_serde::json::{to_json_string, from_json_str};
use helios_fhir::r4::Patient;

// Serialize to JSON
let patient = Patient::default();
let json = to_json_string(&patient)?;

// Deserialize from JSON
let patient: Patient = from_json_str(&json)?;

§XML Serialization (Coming Soon)

use helios_serde::xml::{to_xml_string, from_xml_str};
use helios_fhir::r4::Patient;

// Serialize to XML
let patient = Patient::default();
let xml = to_xml_string(&patient)?;

// Deserialize from XML
let patient: Patient = from_xml_str(&xml)?;

Re-exports§

pub use error::Result;
pub use error::SerdeError;
pub use json::from_json_slice;
pub use json::from_json_str;
pub use json::from_json_value;
pub use json::to_json_string;
pub use json::to_json_string_pretty;
pub use json::to_json_value;
pub use json::to_json_vec;
pub use xml::from_xml_reader;
pub use xml::from_xml_slice;
pub use xml::from_xml_str;
pub use xml::to_xml_string;
pub use xml::to_xml_vec;
pub use xml::to_xml_writer;

Modules§

error
json
JSON serialization wrapper functions for FHIR resources.
xml
XML serialization and deserialization for FHIR resources.