Skip to content

Commit cf865ce

Browse files
committed
Honour PropertyNameAttribute Ignore property in mappings (#4108)
Fixes #4105 (cherry picked from commit b669afd)
1 parent 1d7d30e commit cf865ce

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Nest/CommonAbstractions/SerializationBehavior/PropertyMapping.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ private static IPropertyMapping PropertyMappingFromAttributes(MemberInfo memberI
6565
if (ignore == null && propertyName == null && dataMemberProperty == null) return null;
6666

6767
return new PropertyMapping
68-
{ Name = propertyName?.Name ?? dataMemberProperty?.Name, Ignore = ignore != null };
68+
{
69+
Name = propertyName?.Name ?? dataMemberProperty?.Name,
70+
Ignore = ignore != null || propertyName != null && propertyName.Ignore
71+
};
6972
}
7073
}
7174
}

src/Tests/Tests/ClientConcepts/HighLevel/Mapping/IgnoringProperties.doc.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ namespace Tests.ClientConcepts.HighLevel.Mapping
1616
* === Ignoring properties
1717
* Properties on a POCO can be ignored for mapping purposes in a few ways:
1818
*
19-
* - Using the `Ignore` property on a derived `ElasticsearchPropertyAttribute` type applied to
19+
* - Using the `Ignore` property on a derived `ElasticsearchPropertyAttributeBase` type, such as `TextAttribute`, applied to
2020
* the property that should be ignored on the POCO
2121
*
22+
* - Using the `Ignore` property on `PropertyNameAttribute` applied to a property that should be ignored on the POCO
23+
*
2224
* - Using the `.DefaultMappingFor<TDocument>(Func<ClrTypeMappingDescriptor<TDocument>, IClrTypeMapping<TDocument>>
2325
* selector)` on `ConnectionSettings`
2426
*
@@ -41,8 +43,11 @@ public class CompanyWithAttributesAndPropertiesToIgnore
4143
[Text(Ignore = true)]
4244
public string PropertyToIgnore { get; set; }
4345

46+
[PropertyName("anotherPropertyToIgnore", Ignore = true)]
4447
public string AnotherPropertyToIgnore { get; set; }
4548

49+
public string FluentMappingPropertyToIgnore { get; set; }
50+
4651
[Ignore, JsonIgnore]
4752
public string JsonIgnoredProperty { get; set; }
4853
}
@@ -54,7 +59,7 @@ public void Ignoring()
5459
var connectionSettings = new ConnectionSettings(new InMemoryConnection()) // <1> we're using an in-memory connection, but in your application, you'll want to use an `IConnection` that actually sends a request.
5560
.DisableDirectStreaming() // <2> we disable direct streaming here to capture the request and response bytes. In a production application, you would likely not call this as it adds overhead to each call.
5661
.DefaultMappingFor<CompanyWithAttributesAndPropertiesToIgnore>(m => m
57-
.Ignore(p => p.AnotherPropertyToIgnore)
62+
.Ignore(p => p.FluentMappingPropertyToIgnore)
5863
);
5964

6065
var client = new ElasticClient(connectionSettings);

0 commit comments

Comments
 (0)