Skip to content

XML serialization uses wrong naming convention for primitive extension fields #319

@luisfabib

Description

@luisfabib

model_dump_xml() detects primitive extension fields by looking for a field named
{field_name}_ext (underscore suffix). This naming convention is non-standard.

The FHIR specification uses an underscore prefix in JSON serialisation (e.g. _birthDate
holds the extension for birthDate) and a child element with the same tag in XML. The
internal Pydantic field may follow either convention depending on how the model was generated,
but the lookup in model_dump_xml() assumes the suffix pattern in all cases.

As a result, primitive extension fields are silently missed during XML serialisation, meaning
serialised XML is missing extension data that was present in the Pydantic model.

Impact

  • Round-trip JSON → model → XML → model will silently lose primitive extensions.
  • Profiles that use primitive extensions (e.g. _status, _birthDate) will produce
    non-conformant XML output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions