-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,52 @@ | ||
using Avro.Util; | ||
using Confluent.Kafka; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Fruit.Consumer.AzureFunction | ||
{ | ||
public class FruitMessage | ||
|
||
public class FruitMessage : ISerializer<FruitMessage> | ||
{ | ||
public DateTime? now { get; set; } | ||
public Fruit? fruit { get; set; } | ||
|
||
public FruitMessage(DateTime now, Fruit fruit) | ||
{ | ||
this.now = now; | ||
this.fruit = fruit; | ||
} | ||
public FruitMessage() | ||
{ | ||
} | ||
public byte[] Serialize(FruitMessage data, SerializationContext context) | ||
{ | ||
using (var ms = new MemoryStream()) | ||
{ | ||
var settings = new JsonSerializerSettings(); | ||
settings.ContractResolver = new LowercaseContractResolver(); | ||
var json = JsonConvert.SerializeObject(data, Formatting.Indented, settings); | ||
var writer = new StreamWriter(ms); | ||
|
||
writer.Write(json); | ||
writer.Flush(); | ||
ms.Position = 0; | ||
|
||
return ms.ToArray(); | ||
} | ||
} | ||
} | ||
public class LowercaseContractResolver : DefaultContractResolver | ||
{ | ||
public Date now; | ||
public Fruit fruit; | ||
protected override string ResolvePropertyName(string propertyName) | ||
{ | ||
return propertyName.ToLower(); | ||
} | ||
} | ||
} |