> For the complete documentation index, see [llms.txt](https://php-fhir-tools.ardenexal.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://php-fhir-tools.ardenexal.net/serialization/ig-aware.md).

# Serializing IG Extensions & Profiles

When you generate typed classes for an [Implementation Guide](/code-generation/implementation-guides.md), the serializer must be IG-aware to deserialize those typed extensions and profile subclasses into their PHP classes (rather than the base `Extension` type). Build the service with `createWithIG()`, pointing it at your generated IG output directory and its PSR-4 namespace:

```php
<?php

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

$serializer = FHIRSerializationService::createWithIG(
    igOutputDirectory: '/app/src/FHIRIG',
    igNamespace: 'App\\FHIR\\IG',
    version: FhirVersion::R4B,
);
```

`createWithIG()` scans the base model `Extension` directories plus the optional IG output directory, building an IG type registry. The registry deserializes typed extensions into their PHP classes, resolves `meta.profile` URLs to their profile classes, and picks the right class for a sliced element using the discriminator (the field an IG names to tell sliced entries apart).

{% hint style="info" %}
With no IG arguments, `createWithIG()` (and therefore `createDefault()`, which delegates to it) still registers the base model extensions, so standard typed extensions resolve out of the box. Pass an empty string for `igOutputDirectory` / `igNamespace` to skip IG scanning.
{% endhint %}

The signature is:

```php
public static function createWithIG(
    string $igOutputDirectory = '',
    string $igNamespace = '',
    FhirVersion $version = FhirVersion::R4
): self
```

See the [FHIRBundle guide](/symfony-bundle/configuration.md) for generating IG classes with `fhir:generate-ig`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://php-fhir-tools.ardenexal.net/serialization/ig-aware.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
