> For the complete documentation index, see [llms.txt](https://lanefox.gitbook.io/vault/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lanefox.gitbook.io/vault/guides/getting-started-inventory/serialization.md).

# Serialization

### So you want to 'Save' an Inventory, huh?

Serializing an Inventory is simple. The `InventoryState` class will help you keep track of what an `Inventory` looks like. In order to keep things efficient we only serialize the *reference indexes* for lookup and *not the actual item data*. This keeps saves very small and compact.

Doing this means that we are **not** 1:1 with data being saved and data in the game. It requires some translation work in order to get the data back and forth properly but fortunately it's all auto-magic for you!

### What is stored

```csharp
InventoryState result = MyCharacterInventory.ToState();
```

This will create an `InventoryState` instance for you. We only need to keep track of a few things in order to restore an inventory to it's state. Here's what is actually stored:

1. The Vault Index ID of the Configuration: `int`
2. The Vault Index IDs of the Items in each slot: `List<int>`
3. The stack sizes of the items in each slot: `List<int>`

It's important to note that we have the **means** to restore the *Configuration* and *Content* of an inventory we still have to actually perform the translation from indexes to data.

### How to restore

To-and-From-JSON is built into the `InventoryState` class, but in order to get an `Inventory` back into a particular state you can use the `Initialize` overload to force the `Inventory` to initialize itself and pull from Vault all of the content it needs based on the raw data that was saved.

```
public virtual void Initialize(IUseInventory owner, InventoryState state)
```

This automatically handles converting everything in the `InventoryState` so you don't need to worry about it. You should be able to serialize/deserialize the `InventoryState` however you wish and as long as you throw a valid state at this method it will work.
