# Serializer / Deserializer

### Serializer

You can resolve value of dynamoProperty using by sourceObject.  For example, `alias : id` is resolved to `[x, y].join("_")` It is good for generate `composite key`.

```typescript
@DynamoEntity()
class Entity {
    @DynamoProperty({
        keyType: KeyType.hash,
        propertyName: "id",
        serializer: (arg: SerializerArg<Entity>) => {  // <<<
            const source: Entity = arg.source;
            return [source.x, source.y].join("_");
        }
    })
    __id?: string;

    x: string;
    y: string;

    constructor(x: string, y: string) {
        this.x = x;
        this.y = y;
    }
}
const entity = new Entity("Hello", "World!");
const dynamo = Mapper.formation(entity, Entity);
```

It will be formationed as,

```typescript
{
    "id": {
        "S": "Hello_World!"
    }
}
```

### Deserailizer

Also you can revert using by value of DynamoItem. The `deserializer` returns fragment to return to the original object. You can have only one Serializer and only one Deserializer in each Property. All fragments are merged.

```typescript
@DynamoEntity()
class Entity {
    @DynamoProperty({
        keyType: KeyType.hash,
        propertyName: "id",
        serializer: (arg: SerializerArg<Entity>) => {
            const source: Entity = arg.source;
            return [source.x, source.y].join("_");
        },
        deserializer: (arg: DeserializerArg): Partial<Entity> => { // <<<
          const token: string[] = arg.dynamo.id.S!!.split("_");
          return {
              x: token[0],
              y: token[1]
          };
      }
    })
    __id?: string;

    x: string;
    y: string;

    constructor(x: string, y: string) {
        this.x = x;
        this.y = y;
    }
}
```


---

# Agent Instructions: 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://aerocode.gitbook.io/tynamo/define-entity/define-property/serializer-deserializer.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.
