Skip to main content

Serialization

The following CodeGen settings allow you to configure serialization and deserialization of values in APIMatic generated SDKs.

Array Serialization

This setting adds array serialization scheme for primitive types (applicable to form and query params).

Allowed values are: Indexed, UnIndexed, Plain, CSV, TSV, PSV. There are different ways of representing variable assignments in these formats:

ValueDetails
IndexedThis type of variable assignment includes an index, denoted by square brackets, to indicate which element of an array should be assigned the specified value. For example, variableName[0]=value1 assigns the value value1 to the first element of the variableName array.
UnIndexedThis type of variable assignment does not include an index and is used to add a new value to the end of an array. For example, variableName[]=value1 would append value1 to the end of the variableName array.
PlainThis type of variable assignment is used for non-array variables and assigns a single value to the variable. Multiple assignments can be separated by &. For example, variableName=value1&variableName=value2 assigns the values value1 and value2 to the variableName variable.
CSVThis type of variable assignment is similar to the Plain type, but multiple values are separated by commas without any variable names. For example, variableName=value1,value2 assigns the values value1 and value2 to the variableName variable.
TSVThis type of variable assignment is similar to the CSV type, but the values are separated by tab \t character. For example, variableName=value1\tvalue2 assigns the values value1 and value2 to the variableName variable.
PSVThis type of variable assignment is similar to the CSV type, but the values are separated by pipe | character. For example, variableName=value1|value2 assigns the values value1 and value2 to the variableName variable.

Usage

To use this feature, you need to specify an ArraySerialization value. By default, its value is set to Indexed.

"info": {
...,
"x-codegen-settings": {
"ArraySerialization": "Indexed"
}
}

Language Support

C#JavaPHPPythonRubyTSGo
✔️✔️✔️✔️✔️✔️✔️

Enable JSON Pass Through for Any

Use this setting to decide whether JSON should be passed through any type in the SDK.

Usage

To use this feature, you need to specify a Boolean value. By default, its value is set to false.

"info": {
...,
"x-codegen-settings": {
"EnableJsonPassThroughForAny": false
}
}

Language Support

C#JavaPHPPythonRubyTSGo
✔️✔️✔️✔️✔️✔️

Change in SDK

Configuring this setting has the following effect on the generated SDK:

Value Change
true
JsonObject body = JsonObject.fromJsonString("{\"key1\":\"val1\",\"key2\":\"val2\"}");

jsonObjController.sendSchemaasBodyAsync(body).thenAccept(result -> {
// TODO success callback handler
System.out.println(result);
}).exceptionally(exception -> {
// TODO failure callback handler
exception.printStackTrace();
return null;
});
false (default)
Object body = ApiHelper.deserialize("{\"key1\":\"val1\",\"key2\":\"val2\"}");

jsonObjController.sendSchemaasBodyAsync(body).thenAccept(result -> {
// TODO success callback handler
System.out.println(result);
}).exceptionally(exception -> {
// TODO failure callback handler
exception.printStackTrace();
return null;
});