-
Notifications
You must be signed in to change notification settings - Fork 334
Closed
Labels
Description
Description
C# DateOnly is currently not supported in Newtonsoft so a custom converter needs to be applied. Even when applied, it doesn't appear to be taking effect because I receive the error: NotSupportedException: Serialization and deserialization of 'System.DateOnly' instances are not supported. The unsupported member type is located on type 'System.Object'
Steps to Reproduce
- Register Easy Caching with custom serializer settings
- Attempt to sSerialize Object with EasyCaching Provider
Related code
public sealed class DateOnlyJsonConverter : JsonConverter<DateOnly>
{
public override void WriteJson(JsonWriter writer, DateOnly value, JsonSerializer serializer)
{
writer.WriteValue(value.ToString("O"));
}
public override DateOnly ReadJson(JsonReader reader, Type objectType, DateOnly existingValue, bool hasExistingValue,
JsonSerializer serializer)
{
return DateOnly.FromDateTime(reader.ReadAsDateTime().Value);
}
}
services.AddEasyCaching(options =>
{
Action<Newtonsoft.Json.JsonSerializerSettings> jsonNET = x =>
{
x.Converters.Add(new DateOnlyJsonConverter());
x.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
};
options.WithJson(jsonNET, "json");
options.UseRedis(config =>
{
config.DBConfig.Endpoints.Add(new EasyCaching.Core.Configurations.ServerEndPoint("redis", 6379));
config.SerializerName = "json";
}, "ConfigurationRedisDb");
});
Expected behavior: [What you expected to happen]
The custom converter is used and DateOnly can be serialized/deserialized
Actual behavior: [What actually happened]
DateOnly cannot be serialized/deserialized
Specifications
- Provider : EasyCaching.Redis (version 1.4.1
- Serializer : EasyCaching.Serialization.Json (version 1.4.1
- Interceptor: https://github.com/VahidN/EFCoreSecondLevelCacheInterceptor (version 3.2.4)