In Python 3.7, I want to encode an Avro object to String.
I found examples converting to byte array but not to string.
Code to convert to byte array:
def serialize(mapper, schema):
bytes_writer = io.BytesIO()
encoder = avro.io.BinaryEncoder(bytes_writer)
writer1 = avro.io.DatumWriter(schema)
writer1.write(mapper, encoder)
return bytes_writer.getvalue()
mapper
is a dictionary which will populate the avro object.
io
provides with StringIO
which I assume will need to be used instead of BytesIO
but then what encoder to use with that? How do we serialize this?