Whatever message this page gives is out now! Go check it out!

SerializeAVRO

Last update:
May 18, 2026

Description

Serializes data into an Avro binary format.

Returns

Binary data (or a list containing binary data).
Syntax
serializeAVRO(data, writerSchema [, queryFormat, useCustomSerialization ])

Parameters

ParameterRequiredDescription
dataYesData represented as a struct or an array of structs.
writerSchemaYesThe schema as a string or the absolute path to the schema. Because it is a record, it can define multiple fields which are organized in a JSON array. Each such field identifies the field's name as well as its type. The type can be something simple, like an integer, or something complex, like another record. It can be given as plain string or filepath directly.
queryFormatNoThis parameter is of type string with possible values as row, column or struct.
useCustomSerializationNoTrue/false. Whether to use the customSerializer or not. The default value is true. Note that the custom serialize will always be used for serialization. If false, the Avro serialization will be done using the default ColdFusion behavior.
Example using inline schema
<cfscript>
    // define the Avro schema
    mySchema=   '{  
                    "namespace": "first.example",
                    "type": "record",
                    "name": "User",
                    "fields": [
                        {"name": "name", "type": "string"},
                        {"name": "favorite_number",  "type": ["int","null"]},
                        {"name": "favorite_color", "type": ["string","null"]}
                    ]
                }'
    // set the data that conforms the schema above
    data= {
            "name":"Jack Sparrow",
            "favorite_number":{"int":9},
            "favorite_color":{"string":"red"}
        }
 
    avroSerializeResponse = serializeAVRO(data, mySchema)
writedump(avroSerializeResponse)
</cfscript>
Example using external avsc schema
first.avsc
{  
                    "namespace": "first.example",
                    "type": "record",
                    "name": "User",
                    "fields": [
                        {"name": "name", "type": "string"},
                        {"name": "favorite_number",  "type": ["int","null"]},
                        {"name": "favorite_color", "type": ["string","null"]}
                    ]
  }
avro.cfm
<cfscript>
     //set the data that conforms the schema above
    data= {
            "name":"Jack Sparrow",
            "favorite_number":{"int":9},
            "favorite_color":{"string":"red"}
        }
 
    serializedBinaryAvroData = serializeAVRO(data,  "first.avsc")
    writedump(serializedBinaryAvroData)
 
    deserializedStructData = deSerializeAVRO(serializedBinaryAvroData, "first.avsc", true, true)
    writedump(deserializedStructData)
</cfscript>
avroDataAsAList.cfm
<cfscript>
     //set the data that conforms the schema above
    data= [{
            "name":"Jack Sparrow",
            "favorite_number":{"int":9},
            "favorite_color":{"string":"red"}
        },
        {
            "name":"Barbossa",
            "favorite_number":{"int":7},
            "favorite_color":{"string":"black"}
        }]
 
    serializedBinaryAvroData = serializeAVRO(data,  "a.avsc")
    writedump(serializedBinaryAvroData)
 
    deserializedStructData = deSerializeAVRO(serializedBinaryAvroData, "a.avsc", true, true)
    writedump(deserializedStructData)
</cfscript>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page