> For the complete documentation index, see [llms.txt](https://coldbox.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox.ortusbooks.com/ecosystem/serialization.md).

# Serialization

Serialize objects to structs and JSON in ColdBox with mementifier — composable, fast API responses.

**mementifier** turns your objects into plain structs (their "memento") with fine-grained control — the standard way to build JSON API responses in ColdBox.

```bash
box install mementifier
```

📖 **Full documentation:** [mementifier.ortusbooks.com](https://mementifier.ortusbooks.com)

## Quick Example

{% tabs %}
{% tab title="BoxLang" %}

```javascript
// models/User.bx
class accessors="true" {

    this.memento = {
        defaultIncludes : [ "id", "email", "name" ],
        defaultExcludes : [ "password" ]
    }

    property name="id"
    property name="email"
    property name="name"
    property name="password"
}
```

{% endtab %}

{% tab title="CFML" %}

```javascript
// models/User.cfc
component accessors="true" {

    this.memento = {
        defaultIncludes : [ "id", "email", "name" ],
        defaultExcludes : [ "password" ]
    }

    property name="id"
    property name="email"
    property name="name"
    property name="password"
}
```

{% endtab %}
{% endtabs %}

```javascript
// In a handler
function show( event, rc, prc ){
    var user = userService.get( rc.id )

    event.renderData(
        type : "json",
        data : user.getMemento()   // password never leaves the server
    )
}
```

## Why Not `serializeJSON( user )`?

Raw serialization leaks internal state, follows relationships infinitely deep, and breaks on lazily-loaded ORM proxies. mementifier gives you an explicit contract:

* `defaultIncludes` / `defaultExcludes` — the default shape
* Per-call overrides: `user.getMemento( includes : [ "roles" ] )`
* Nested mementos for relationships, with their own include rules
* Custom formatters per property (dates, masks, computed values)

## When to Use It

* JSON API responses (pairs with the [REST Handler](/digging-deeper/rest-handler.md))
* Serializing ORM/Quick entities safely
* Any time an object crosses a boundary: APIs, queues, caches

## See Also

* [Data & Persistence](/ecosystem/data-and-persistence.md) — ORM options
* [Rendering Data](/the-basics/event-handlers/rendering-data.md) — `renderData()` types


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox.ortusbooks.com/ecosystem/serialization.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
