PHPackages                             ardenexal/fhir-serialization - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. ardenexal/fhir-serialization

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

ardenexal/fhir-serialization
============================

PHP library for FHIR JSON serialization, deserialization, and validation

0.2(2mo ago)14201MITPHPPHP &gt;=8.3

Since Feb 17Pushed 2mo agoCompare

[ Source](https://github.com/Ardenexal/fhir-serialization)[ Packagist](https://packagist.org/packages/ardenexal/fhir-serialization)[ RSS](/packages/ardenexal-fhir-serialization/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (14)Versions (7)Used By (1)

FHIR Serialization Component
============================

[](#fhir-serialization-component)

PHP library for FHIR JSON and XML serialization and deserialization, built on top of the Symfony Serializer component.

Features
--------

[](#features)

- FHIR-compliant JSON and XML serialization
- Configurable validation modes (strict/lenient/performance)
- Auto-detection of format and resource type
- Round-trip serialization testing
- Debug information support

Quick Start
-----------

[](#quick-start)

```
use Ardenexal\FHIRTools\Component\Serialization\FHIRSerializationService;

// Serialize to JSON
$json = $service->serializeToJson($patient);

// Serialize to XML
$xml = $service->serializeToXml($patient);

// Deserialize from JSON
$patient = $service->deserializeFromJson($json, FHIRPatient::class);

// Deserialize from XML
$patient = $service->deserializeFromXml($xml, FHIRPatient::class);

// Auto-detect format and resource type
$resource = $service->deserialize($data);
```

Serialization Contexts
----------------------

[](#serialization-contexts)

The `FHIRSerializationContextFactory` provides pre-configured contexts:

```
use Ardenexal\FHIRTools\Component\Serialization\Context\FHIRSerializationContextFactory;

$factory = new FHIRSerializationContextFactory();

// Default contexts
$jsonContext = $factory->createJsonContext();
$xmlContext = $factory->createXmlContext();

// Strict validation for production
$strictContext = $factory->createStrictContext('json');

// Lenient for development
$lenientContext = $factory->createLenientContext('json');

// Performance-optimized (minimal validation)
$perfContext = $factory->createPerformanceContext('json');

// Debug mode with detailed information
$debugContext = $factory->createDebugContext('json');
```

### Context Options

[](#context-options)

All contexts support these FHIR-specific options:

OptionDefaultDescription`fhir_strict_validation``true`Enable strict FHIR validation`fhir_include_extensions``true`Include FHIR extensions`fhir_include_metadata``true`Include metadata elements`fhir_unknown_element_policy``ignore`How to handle unknown elements (`ignore`, `error`, `preserve`)`fhir_validate_references``false`Validate FHIR referencesPass custom overrides to any factory method:

```
$context = $factory->createJsonContext([
    'fhir_strict_validation' => false,
    'max_depth' => 20,
]);
```

Round-Trip Testing
------------------

[](#round-trip-testing)

Verify serialization integrity:

```
// Serialize then deserialize, returns the deserialized object
$roundTripped = $service->roundTripTest($patient, 'json');
$roundTripped = $service->roundTripTest($patient, 'xml');
```

Error Handling
--------------

[](#error-handling)

```
use Ardenexal\FHIRTools\Component\Serialization\Exception\FHIRSerializationException;

try {
    $patient = $service->deserializeFromJson($invalidJson, FHIRPatient::class);
} catch (FHIRSerializationException $e) {
    echo "Serialization error: {$e->getMessage()}";
}
```

Symfony Integration
-------------------

[](#symfony-integration)

When used with the FHIRBundle, the service is automatically registered and available via dependency injection:

```
use Ardenexal\FHIRTools\Component\Serialization\FHIRSerializationService;

class PatientService
{
    public function __construct(
        private readonly FHIRSerializationService $serializer,
    ) {}

    public function processPatientJson(string $json): object
    {
        return $this->serializer->deserializeFromJson($json, FHIRPatient::class);
    }
}
```

Requirements
------------

[](#requirements)

- **PHP**: 8.3 or higher

License
-------

[](#license)

This component is released under the MIT License. See the [LICENSE](../../../LICENSE) file for details.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance86

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

6

Last Release

60d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/40bdcfdbd80eda272029a422eee67464bf9b82f26271252e9425a1d583c03d34?d=identicon)[Ardenexal](/maintainers/Ardenexal)

---

Top Contributors

[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (10 commits)")[![Ardenexal](https://avatars.githubusercontent.com/u/2852475?v=4)](https://github.com/Ardenexal "Ardenexal (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ardenexal-fhir-serialization/health.svg)

```
[![Health](https://phpackages.com/badges/ardenexal-fhir-serialization/health.svg)](https://phpackages.com/packages/ardenexal-fhir-serialization)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[symfony/serializer-pack

A pack for the Symfony serializer

1.1k28.2M221](/packages/symfony-serializer-pack)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[api-platform/serializer

API Platform core Serializer

223.4M31](/packages/api-platform-serializer)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
