# Serialize

Required Frends version: 5.7+

Required .NET version: 8.0

Compatible Agents: Unknown

Source code: <https://github.com/FrendsPlatform/Frends.Avro>

{% tabs %}
{% tab title="Parameter: Input" %}

| Name                      | Description                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Json : `String`           | <p>Input JSON string that can be both single objects and arrays of objects.</p><p>The JSON data will be serialized according to the provided Avro schema.</p><p><br>Default: <code>-</code><br>Example: <code>Single object: { "name": "Jerry", "age": 30, "city": "New York" } Array of objects: \[{ "name": "John", "age": 30 }, { "name": "Jane", "age": 25 }]</code></p>                                              |
| Schema : `String`         | <p>Avro Schema definition in JSON format that defines the structure of the data to be serialized.</p><p>Must be a valid Avro schema that matches the structure of the input JSON data.</p><p><br>Default: <code>-</code><br>Example: <code>{ "type": "record", "name": "Person", "fields": \[ { "name": "name", "type": "string" }, { "name": "age", "type": "int" }, { "name": "city", "type": "string" } ] }</code></p> |
| TargetFilePath : `String` | <p>Full path to the target file where the serialized Avro data will be stored.</p><p>The directory must exist and the file must not already exist (unless overwrite is enabled).</p><p><br>Default: <code>-</code><br>Example: <code>Windows: C:\data\output\myfile.avro Linux/Mac: /home/user/data/myfile.avro</code></p>                                                                                                |
| {% endtab %}              |                                                                                                                                                                                                                                                                                                                                                                                                                           |

{% tab title="Parameter: Options" %}

| Name                             | Description                                                                                                                                                                                                                                                                                                                                  |
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ThrowErrorOnFailure : `Boolean`  | <p>Determines error handling behavior. If true, throws an exception when serialization fails.</p><p>If false, returns error information in the Result object instead of throwing.</p><p><br>Default: <code>True</code><br>Example: <code>true</code></p>                                                                                     |
| ErrorMessageOnFailure : `String` | <p>Custom error message to use when ThrowErrorOnFailure is false and an error occurs.</p><p>If null or empty, the original exception message will be used.</p><p>This allows for user-friendly error messages in automated workflows.</p><p><br>Default: <code>-</code><br>Example: <code>Failed to serialize data to Avro format</code></p> |
| {% endtab %}                     |                                                                                                                                                                                                                                                                                                                                              |

{% tab title="Result: Result" %}

| Name                | Description                                                                                                                                                                                                                                     |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Success : `Boolean` | <p>Indicates whether the serialization operation completed successfully. True if the JSON data was successfully serialized to Avro format, false if an error occurred.<br>Example: <code>true</code></p>                                        |
| FilePath : `String` | <p>Full path to the created Avro file when serialization is successful. Empty string when serialization fails.<br>Example: <code>C:\results\myfile.avro</code></p>                                                                              |
| Error : `Error`     | Error information when the serialization task fails and ThrowErrorOnFailure option is set to false. Contains detailed error message and additional debugging information. Null when the operation succeeds or when ThrowErrorOnFailure is true. |
| {% endtab %}        |                                                                                                                                                                                                                                                 |

{% tab title="Changelog" %}

## Changelog

### \[2.0.0] - 2025-08-07

#### Changed

* \[Breaking] Renamed `OutputPath` parameter to `TargetFilePath` in Input tab
* Updated Result structure to include Success boolean and Error object

#### Added

* Added new Options tab with error handling parameters (ThrowErrorOnFailure, ErrorMessageOnFailure)

### \[1.0.0] - 2024-05-23

#### Added

* Initial implementation
  {% endtab %}
  {% endtabs %}
