<commit_before># Mapping

The metadata mapping allows you to expose your object structure to the serializer.

## Factory

In order to create your metadatas, the library uses a factory relying on a loader. Let's create a factory: 

``` php
use Ivory\Serializer\Mapping\Factory\ClassMetadataFactory;

$classMetadataFactory = new ClassMetadataFactory();
// or
$classMetadataFactory = new ClassMetadataFactory($loader);
```

In production, it is highly recommended to use the cache factory: 

``` php
use Ivory\Serializer\Mapping\Factory\CacheClassMetadataFactory;
use Ivory\Serializer\Mapping\Factory\ClassMetadataFactory;
use Ivory\Serializer\Registry\TypeRegistry;
use Ivory\Serializer\Type\ObjectType;
use Ivory\Serializer\Type\Type;

$classMetadataFactory = new ClassMetadataFactory();
$cacheClassMetadataFactory = new CacheClassMetadataFactory($classMetadataFactory, $psr6CachePool);

$typeRegistry = TypeRegistry::create([
    Type::OBJECT => new ObjectType($cacheClassMetadataFactory),
]);

$serializer = new Serializer(new Navigator($typeRegistry));
```

## Loader

### Reflection

The reflection loader is the default one if doctrine annotation is not installed. It is able to find all your 
properties for serialization but will not be sufficient for deserialization since it is not able to parse complex 
types.

``` php
use Ivory\Serializer\Mapping\Loader\ReflectionClassMetadataLoader;

$loader = new ReflectionClassMetadataLoader();
```

### Annotation

The annotation loader works the same way as the reflection one except that it also parses annotations.

``` php
use Ivory\Serializer\Mapping\Loader\AnnotationClassMetadataLoader;

$loader = new AnnotationClassMetadataLoader();
```

### XML

The XML loader allows you to use a XML mapping file:

``` php
use Ivory\Serializer\Mapping\Loader\XmlClassMetadataLoader;

$loader = new XmlClassMetadataLoader('/path/to/file.xml');
```

### YAML

The YAML loader allows you to use a YAML mapping file:

``` php
use Ivory\Serializer\Mapping\Loader\YamlClassMetadataLoader;

$loader = new YamlClassMetadataLoader('/path/to/file.yml');
```

### JSON

The JSON loader allows you to use a JSON mapping file:

``` php
use Ivory\Serializer\Mapping\Loader\JsonClassMetadataLoader;

$loader = new JsonClassMetadataLoader('/path/to/file.json');
```

### Chain
<commit_msg>[Doc] Add links to mapping references<commit_after># Mapping

The metadata mapping allows you to expose your object structure to the serializer.

## Factory

In order to create your metadatas, the library uses a factory relying on a loader. Let's create a factory: 

``` php
use Ivory\Serializer\Mapping\Factory\ClassMetadataFactory;

$classMetadataFactory = new ClassMetadataFactory();
// or
$classMetadataFactory = new ClassMetadataFactory($loader);
```

In production, it is highly recommended to use the cache factory: 

``` php
use Ivory\Serializer\Mapping\Factory\CacheClassMetadataFactory;
use Ivory\Serializer\Mapping\Factory\ClassMetadataFactory;
use Ivory\Serializer\Registry\TypeRegistry;
use Ivory\Serializer\Type\ObjectType;
use Ivory\Serializer\Type\Type;

$classMetadataFactory = new ClassMetadataFactory();
$cacheClassMetadataFactory = new CacheClassMetadataFactory($classMetadataFactory, $psr6CachePool);

$typeRegistry = TypeRegistry::create([
    Type::OBJECT => new ObjectType($cacheClassMetadataFactory),
]);

$serializer = new Serializer(new Navigator($typeRegistry));
```

## Loader

### Reflection

The reflection loader is the default one if doctrine annotation is not installed. It is able to find all your 
properties for serialization but will not be sufficient for deserialization since it is not able to parse complex 
types.

``` php
use Ivory\Serializer\Mapping\Loader\ReflectionClassMetadataLoader;

$loader = new ReflectionClassMetadataLoader();
```

### Annotation

The annotation loader works the same way as the reflection one except that it also parses annotations.

``` php
use Ivory\Serializer\Mapping\Loader\AnnotationClassMetadataLoader;

$loader = new AnnotationClassMetadataLoader();
```

An example of all annotations are available [here](/doc/mapping/annotation-reference.md).

### XML

The XML loader allows you to use a XML mapping file:

``` php
use Ivory\Serializer\Mapping\Loader\XmlClassMetadataLoader;

$loader = new XmlClassMetadataLoader('/path/to/file.xml');
```

An example of all annotations are available [here](/doc/mapping/xml-reference.md).

### YAML

The YAML loader allows you to use a YAML mapping file:

``` php
use Ivory\Serializer\Mapping\Loader\YamlClassMetadataLoader;

$loader = new YamlClassMetadataLoader('/path/to/file.yml');
```

An example of all annotations are available [here](/doc/mapping/yaml-reference.md).

### JSON

The JSON loader allows you to use a JSON mapping file:

``` php
use Ivory\Serializer\Mapping\Loader\JsonClassMetadataLoader;

$loader = new JsonClassMetadataLoader('/path/to/file.json');
```

An example of all annotations are available [here](/doc/mapping/json-reference.md).

### Chain

{'fraction_non_alphanumeric': 0.0991008991008991, 'fraction_numerical': 0.0003996003996003996, 'mean_word_length': 5.621693121693122, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2587376', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1332, 'n_words': 455}