public byte[] Serialize(T o, SerializationContext context) { if (o == null) { return(null); } using (var stream = new MemoryStream()) { serializer.Serialize(stream, o, typeof(T), CancellationToken.None); return(stream.ToArray()); } }
public void Serialize() { var client = new SchemaRegistryClient(TestEnvironment.SchemaRegistryUri, TestEnvironment.Credential); #region Snippet:Serialize var employee = new Employee { Age = 42, Name = "John Doe" }; string groupName = "<schema_group_name>"; using var memoryStream = new MemoryStream(); var serializer = new SchemaRegistryAvroObjectSerializer(client, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); serializer.Serialize(memoryStream, employee, typeof(Employee), CancellationToken.None); #endregion }
public void Serialize() { string groupName = TestEnvironment.SchemaRegistryGroup; #region Snippet:SchemaRegistryAvroSerialize var employee = new Employee { Age = 42, Name = "John Doe" }; using var memoryStream = new MemoryStream(); var serializer = new SchemaRegistryAvroObjectSerializer(schemaRegistryClient, groupName, new SchemaRegistryAvroObjectSerializerOptions { AutoRegisterSchemas = true }); serializer.Serialize(memoryStream, employee, typeof(Employee), CancellationToken.None); #endregion Assert.IsTrue(memoryStream.Length > 0); _memoryStreamBytes = memoryStream.ToArray(); }