diff --git a/Btms.SensitiveData/SensitiveFieldsProvider.cs b/Btms.SensitiveData/SensitiveFieldsProvider.cs index b56f5d2..1589aca 100644 --- a/Btms.SensitiveData/SensitiveFieldsProvider.cs +++ b/Btms.SensitiveData/SensitiveFieldsProvider.cs @@ -1,5 +1,6 @@ using System.Reflection; using System.Text.Json; +using System.Text.Json.Serialization; namespace Btms.SensitiveData; @@ -49,8 +50,10 @@ private static List GetSensitiveFields(string root, Type type) var list = new List(); foreach (var property in type.GetProperties()) { + var jsonPropertyNameAttribute = property.GetCustomAttribute(); + var propertyName = jsonPropertyNameAttribute != null ? jsonPropertyNameAttribute.Name : property.Name; string currentPath; - currentPath = string.IsNullOrEmpty(root) ? $"{namingPolicy.ConvertName(property.Name)}" : $"{namingPolicy.ConvertName(root)}.{namingPolicy.ConvertName(property.Name)}"; + currentPath = string.IsNullOrEmpty(root) ? $"{namingPolicy.ConvertName(propertyName)}" : $"{namingPolicy.ConvertName(root)}.{namingPolicy.ConvertName(propertyName)}"; if (property.CustomAttributes.Any(x => x.AttributeType == typeof(SensitiveDataAttribute))) {