You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
613 B
24 lines
613 B
using System.Text.Json.Serialization.Metadata;
|
|
|
|
namespace Recyclarr.Json;
|
|
|
|
[AttributeUsage(AttributeTargets.Property)]
|
|
public sealed class JsonNoSerializeAttribute : Attribute
|
|
{
|
|
}
|
|
|
|
public static class JsonSerializationModifiers
|
|
{
|
|
public static void IgnoreNoSerializeAttribute(JsonTypeInfo type)
|
|
{
|
|
var propertiesToRemove = type.Properties
|
|
.Where(x => x.AttributeProvider?.IsDefined(typeof(JsonNoSerializeAttribute), false) ?? false)
|
|
.ToList();
|
|
|
|
foreach (var prop in propertiesToRemove)
|
|
{
|
|
prop.ShouldSerialize = (_, _) => false;
|
|
}
|
|
}
|
|
}
|