Skip to content

Commit

Permalink
Limit the serialization binder to a base type
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Oct 2, 2023
1 parent d270c27 commit a92919d
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Data;
using System.Data.Common;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using NHibernate;
using NHibernate.Engine;
using NHibernate.SqlTypes;
Expand All @@ -14,6 +15,8 @@ namespace Shoko.Server.Databases.NHIbernate;

public class FilterExpressionConverter : TypeConverter, IUserType
{
private static readonly ISerializationBinder _binder = new SimpleNameSerializationBinder(typeof(FilterExpression));

public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return typeof(FilterExpression<bool>).IsAssignableFrom(sourceType);
Expand All @@ -32,7 +35,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, System.Global
{
MissingMemberHandling = MissingMemberHandling.Ignore,
TypeNameHandling = TypeNameHandling.Objects,
SerializationBinder = new SimpleNameSerializationBinder(),
SerializationBinder = _binder,
Error = (_, args) =>
{
LogManager.GetCurrentClassLogger().Error(args.ErrorContext.Error);
Expand Down Expand Up @@ -62,7 +65,7 @@ public override object ConvertTo(ITypeDescriptorContext context, System.Globaliz
{
MissingMemberHandling = MissingMemberHandling.Ignore,
TypeNameHandling = TypeNameHandling.Objects,
SerializationBinder = new SimpleNameSerializationBinder(),
SerializationBinder = _binder,
});
}

Expand Down

0 comments on commit a92919d

Please sign in to comment.