### Convert JSON to Avro Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Converts a JSON serialized object into an Avro formatted byte array, optionally using a specified codec for compression. Includes an example demonstrating the conversion process. ```csharp byte[] resultAvro = Json2Avro(string json, CodecType codecType); example: //Arrange var user = _fixture.Creat(); var jsonData = JsonConvert.SerializeObject(user); //Act var resultAvro = AvroConvert.Json2Avro(jsonData); //Assert var expectedAvro = AvroConvert.Serialize(user); Assert.Equal(expectedAvro, resultAvro); ``` -------------------------------- ### Merge Avro Objects Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Merges multiple Avro serialized objects of a specified type into a single byte array representing a collection of those objects. Includes an example demonstrating Arrange, Act, and Assert steps. ```csharp byte[] result = AvroConvert.Merge(IEnumerable avroObjects); example: //Arrange var users = _fixture.CreateMany(); var avroObjects = users.Select(AvroConvert.Serialize) //Act var result = AvroConvert.Merge(avroObjects); //Assert var deserializedResult = AvroConvert.Deserialize>(result); ``` -------------------------------- ### Headless Avro Serialization and Deserialization Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Performs Avro serialization and deserialization using explicitly provided schemas. The schemas for serialization and deserialization must be identical. ```csharp string schema = "{\"type\":\"record\",\"name\":\"user.User\",\"fields\":[{\"name\":\"name\",\"type\":,\"string\"},{\"name\":\"favorite_number\",\"type\":[\"null\",\"int\"]},{\"name\":\"favorite_color\",\"type\":[\"null\",\"string\"]}]}"; var serialized = AvroConvert.SerializeHeadless(toSerialize, schema); var deserialized = AvroConvert.DeserializeHeadless(serialized, schema); ``` -------------------------------- ### Headless Serialization and Deserialization Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Performs serialization and deserialization using explicitly provided Avro schemas. The schemas for serialization and deserialization must be exactly the same. ```APIDOC ## Headless serialization and deserialization Performs serialization and deserialization using explicitly provided Avro schemas. The schemas for serialization and deserialization must be exactly the same. ### Method Signatures ```csharp byte[] AvroConvert.SerializeHeadless(object toSerialize, string schema) T AvroConvert.DeserializeHeadless(byte[] serializedData, string schema) ``` ### Example Schema ```json { "type": "record", "name": "user.User", "fields": [ {"name": "name", "type": "string"}, {"name": "favorite_number", "type": ["null", "int"]}, {"name": "favorite_color", "type": ["null", "string"]} ] } ``` ``` -------------------------------- ### Serialization Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Serializes an object into Avro format. Supports various compression codecs for efficient storage and transmission. ```APIDOC ## Serialization Serializes an object into Avro format. Supports various compression codecs for efficient storage and transmission. ### Method Signature ```csharp byte[] AvroConvert.Serialize(object yourObject) byte[] AvroConvert.Serialize(object yourObject, CodecType codecType) ``` ### Supported Encoding Types - Null (default) - Deflate - Snappy - GZip - Brotli ``` -------------------------------- ### Generate C# Model from Avro Schema or File Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.Schema.md Generates C# .NET classes (models) from an Avro file or schema. This is the inverse operation of GenerateSchema. ```csharp //Given is schema var schema = AvroConvert.GenerateSchema(typeof(User)); { "type":"record", "name":"AvroConvertComponentTests.User", "fields":[ { "name":"name", "type":"string" }, { "name":"favorite_number", "type":[ "null", "int" ] }, { "name":"favorite_color", "type":"string" } ] } //Action string resultModel = AvroConvert.GenerateModel(schema); //string // OR string resultModel = AvroConvert.GenerateModel(avroFileContent); //byte[] //Produces following model: public class User { public string name { get; set; } public int? favorite_number { get; set; } public string? favorite_color { get; set; } } ``` -------------------------------- ### Serialize Object to Avro Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Serializes a given object into a byte array using Avro format. Supports specifying a codec for compression. ```csharp byte[] avroObject = AvroConvert.Serialize(object yourObject); ``` ```csharp byte[] avroObject = AvroConvert.Serialize(object yourObject, CodecType.Snappy); ``` -------------------------------- ### Generate Avro Schema for Simple C# Class Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.Schema.md Generates an Avro schema in JSON format for a simple C# class without attributes. Properties are mapped to Avro fields. ```csharp //Model public class SimpleTestClass { public string justSomeProperty { get; set; } public long andLongProperty { get; set; } } //Action string schemaInJsonFormat = AvroConvert.GenerateSchema(typeof(SimpleTestClass)); //Produces following schema: { "type":"record", "name":"AvroConvert.SimpleTestClass", "fields":[ { "name":"justSomeProperty", "type":[ "null", "string" ] }, { "name":"andLongProperty", "type":"long" } ] } ``` -------------------------------- ### Serialize object to Avro format Source: https://github.com/adrianstrugala/avroconvert/blob/master/README.md Use this method to serialize a .NET object into Avro byte array format. Ensure the object's type is compatible with Avro schema. ```csharp byte[] avroObject = AvroConvert.Serialize(object yourObject); ``` -------------------------------- ### Generate C# model from Avro data or schema Source: https://github.com/adrianstrugala/avroconvert/blob/master/README.md Automatically generate C# class definitions based on an Avro object's schema or a provided Avro schema file. This simplifies mapping Avro data to .NET types. ```csharp string resultModel = AvroConvert.GenerateModel(avroObject); ``` -------------------------------- ### Generate Avro Schema for C# Class with Attributes Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.Schema.md Generates an Avro schema for a C# class decorated with attributes like DataContract, DataMember, Description, DefaultValue, and NullableSchema. These attributes influence the schema's name, documentation, field names, types, and default values. ```csharp //Model [DataContract(Name = "User", Namespace = "userspace")] [Description("This is Doc of User Class")] public class AttributeClass { [DataMember(Name = "name")] [Description("This is Doc of record field")] public string StringProperty { get; set; } [DataMember(Name = "favorite_number")] [DefaultValue(2137)] public int? NullableIntPropertyWithDefaultValue { get; set; } [DataMember(Name = "not_favorite_number")] [NullableSchema] public int AnotherWayOrIndicatingNullableProperty { get; set; } [DataMember(Name = "favorite_color")] [NullableSchema] public string AndAnotherString { get; set; } } //Action string schemaInJsonFormat = AvroConvert.GenerateSchema(typeof(AttributeClass)); //Produces following schema: { "type": "record", "name": "userspace.User", "doc": "This is Doc of User Class", "fields": [ { "name": "name", "doc": "This is Doc of record field", "aliases": [ "StringProperty" ], "type": "string" }, { "name": "favorite_number", "aliases": [ "NullableIntPropertyWithDefaultValue" ], "type": [ "int", "null" ], "default": 2137 }, { "name": "not_favorite_number", "aliases": [ "AnotherWayOrIndicatingNullableProperty" ], "type": [ "null", "int" ] }, { "name": "favorite_color", "aliases": [ "AndAnotherString" ], "type": [ "null", "string" ] } ] } ``` -------------------------------- ### Deserialize large Avro collections one by one Source: https://github.com/adrianstrugala/avroconvert/blob/master/README.md Efficiently process large collections of Avro objects without loading the entire dataset into memory. Use this for memory-constrained environments. ```csharp using (var reader = AvroConvert.OpenDeserializer(new MemoryStream(avroObject))) { while (reader.HasNext()) { var item = reader.ReadNext(); // process item } } ``` -------------------------------- ### Deserialization Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Deserializes Avro data back into an object. Supports generic type inference, dynamic type casting, and handling default values from the schema. ```APIDOC ## Deserialization Deserializes Avro data back into an object. Supports generic type inference, dynamic type casting, and handling default values from the schema. ### Method Signatures ```csharp // Using generic method T AvroConvert.Deserialize(byte[] avroObject) // Using dynamic method object AvroConvert.Deserialize(byte[] avroObject, Type targetType) // Deserialization to dynamic result dynamic AvroConvert.Deserialize(byte[] avroObject) ``` ### Deserialization with Default Values When deserializing an object where a property value is null, but the schema contains information about a default value, AvroConvert will apply that default value. **Example Model:** ```csharp public class DefaultValueClass { [DefaultValue("Let's go")] public string justSomeProperty { get; set; } [DefaultValue(2137)] public long? andLongProperty { get; set; } } ``` **Deserializing object with null data:** ```csharp DefaultValueClass deserializedObject = AvroConvert.Deserialize(byte[] avroObject); // Produces following object: // deserializedObject.justSomeProperty == "Let's go" // deserializedObject.andLongProperty == 2137 ``` ``` -------------------------------- ### Deserialize Avro object to .NET type Source: https://github.com/adrianstrugala/avroconvert/blob/master/README.md Deserialize an Avro byte array back into a specified .NET object type. The target type must match the schema used during serialization. ```csharp CustomClass deserializedObject = AvroConvert.Deserialize(byte[] avroObject); ``` -------------------------------- ### Deserialize Avro with Default Values Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Deserializes Avro data, applying default values defined in the schema when a property value is null. This is useful for ensuring objects have expected values even if not explicitly provided in the serialized data. ```csharp //Model used for serialization public class DefaultValueClass { [DefaultValue("Let's go")] public string justSomeProperty { get; set; } [DefaultValue(2137)] public long? andLongProperty { get; set; } } //Deserializing object with null data DefaultValueClass deserializedObject = AvroConvert.Deserialize(byte[] avroObject); //Produces following object: > deserializedObject.justSomeProperty > "Let's go" > deserializedObject.andLongProperty > 2137 ``` -------------------------------- ### Deserialization of Large Collections Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Efficiently deserializes a large collection of Avro objects one by one without loading the entire dataset into memory. ```APIDOC ## Deserialization of large collection of Avro objects one by one Efficiently deserializes a large collection of Avro objects one by one without loading the entire dataset into memory. ### Method Signature ```csharp using (var reader = AvroConvert.OpenDeserializer(Stream stream)) { while (reader.HasNext()) { var item = reader.ReadNext(); // process item } } ``` ``` -------------------------------- ### Convert Avro to JSON directly Source: https://github.com/adrianstrugala/avroconvert/blob/master/README.md Convert Avro encoded data directly into a JSON string representation. This is useful for debugging or interoperability with systems that prefer JSON. ```csharp var resultJson = AvroConvert.Avro2Json(avroObject); ``` -------------------------------- ### Json2Avro Conversion Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Converts JSON serialized data directly into Avro format, optionally applying a specified codec for compression. ```APIDOC ## Json2Avro Converts JSON serialized object directly to Avro format. ### Method Signature ```csharp byte[] AvroConvert.Json2Avro(string json, CodecType codecType = CodecType.Null) ``` ### Example Usage ```csharp //Arrange var user = _fixture.Create(); var jsonData = JsonConvert.SerializeObject(user); //Act var resultAvro = AvroConvert.Json2Avro(jsonData); //Assert var expectedAvro = AvroConvert.Serialize(user); Assert.Equal(expectedAvro, resultAvro); ``` ``` -------------------------------- ### Convert Avro to JSON Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Converts Avro serialized data directly into a JSON formatted string. This is useful for APIs that require JSON output or for debugging. ```csharp string resultJson = AvroConvert.Json2Avro(byte[] avroData); example: //Arrange var user = _fixture.Creat(); var avroData = AvroConvert.Serialize(user); //Act var resultJson = AvroConvert.Avro2Json(avroData); //Assert var expectedJson = JsonConvert.SerializeObject(user); Assert.Equal(expectedJson, resultJson); ``` -------------------------------- ### Deserialize Avro to Object Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Deserializes a byte array containing Avro data back into a specified object type. Can be used with generic or dynamic type inference. ```csharp //Using generic method CustomClass deserializedObject = AvroConvert.Deserialize(byte[] avroObject); ``` ```csharp //Using dynamic method CustomClass deserializedObject = AvroConvert.Deserialize(byte[] avroObject, typeof(CustomClass)); ``` ```csharp //Deserialization to dynamic result dynamic deserializedObject = AvroConvert.Deserialize(byte[] avroObject); ``` -------------------------------- ### Avro2Json Conversion Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Converts Avro serialized data directly into a JSON formatted string. This is useful for minimal API implementations or when JSON output is required. ```APIDOC ## Avro2Json Converts Avro serialized object directly to JSON format. Useful for a minimal API approach. ### Method Signature ```csharp string AvroConvert.Avro2Json(byte[] avroData) ``` ### Example Usage ```csharp //Arrange var user = _fixture.Create(); var avroData = AvroConvert.Serialize(user); //Act var resultJson = AvroConvert.Avro2Json(avroData); //Assert var expectedJson = JsonConvert.SerializeObject(user); Assert.Equal(expectedJson, resultJson); ``` ``` -------------------------------- ### Read Avro Schema from Avro Encoded Object Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.Schema.md Extracts the Avro schema in JSON format from a given Avro encoded object. ```csharp string schemaInJsonFormat = AvroConvert.GetSchema(byte[] avroObject) ``` -------------------------------- ### Merge Avro Objects Source: https://github.com/adrianstrugala/avroconvert/blob/master/docs/Documentation.md Merges multiple Avro objects of a specified type into a single collection of that type. ```APIDOC ## Merge Merges multiple Avro objects of type T into one of type IEnumerable of T. ### Method Signature ```csharp byte[] AvroConvert.Merge(IEnumerable avroObjects) ``` ### Example Usage ```csharp //Arrange var users = _fixture.CreateMany(); var avroObjects = users.Select(AvroConvert.Serialize); //Act var result = AvroConvert.Merge(avroObjects); //Assert var deserializedResult = AvroConvert.Deserialize>(result); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.