Skip to content

Switching Json Serializer

Elvin (Tharindu) Thudugala edited this page Aug 19, 2022 · 1 revision

Switching Jason Serializer and use Newtonsoft.Json when implementing INotificationSerializer

using Newtonsoft.Json;

public class MyNotificationSerializer : INotificationSerializer
{
	public virtual TValue Deserialize<TValue>(string json)
	{
		return JsonConvert.DeserializeObject<TValue>(json);
	}

	public virtual string Serialize<TValue>(TValue value)
	{
		return JsonSerializer.Serialize(value);
	}
}    
public static class MauiProgram
{
	public static MauiApp CreateMauiApp()
	{
		var builder = MauiApp.CreateBuilder();
		builder
			.UseMauiApp<App>()
                        ....
			.UseLocalNotification(config =>
			{
                        	config.SetSerializer(new MyNotificationSerializer())
			});
                return builder.Build();
	}
}