ecs-dotnet
ecs-dotnet copied to clipboard
[BUG] Unable to subslass property of a property
ECS integration/library project(s) (e.g. Elastic.CommonSchema.Serilog): 1.5.3
ECS schema version (e.g. 1.4.0): 1.5.0
ECS .NET assembly version (e.g. 1.4.2): 1.5.3
Elasticsearch version (if applicable): n/a
.NET framework / OS: ASP.NET Core 3.1
Description of the problem, including expected versus actual behavior:
ECS 1.5 doesn't have property id in HttpRequest, so I decided to subclass it in order to have request id in place. I've tried two things:
- I've created
CustomHttpRequestwhich inheritsHttpRequestand addsIdproperty. However, serialized event doesn't containIdproperty becauseSystem.Text.JsonSerializerhas a limited support of lower-level properties: "You can get polymorphic serialization for lower-level objects if you define them as type object"
public class CustomHttpRequest : HttpRequest
{
[DataMember(Name = "id")]
public string? Id { get; set; }
}
- I've created
CustomHttpwhich inheritsHttp, adds property of typeCustomHttpRequestasRequestand hides original property. During serialization it fails with an error "The JSON property name for 'MyNamespace.CustomHttp.Request' collides with another property", obviously serializer doesn't recognize that the property is hidden,
public class CustomHttp : Http
{
public new CustomHttpRequest? Request { get; set; }
}
I'd expect a standard way of extending lower-level properties (apart from resurrecting this repo and updating it to the latest versions of ECS of course 😃 ).
Steps to reproduce:
See above
We do support injecting new properties on fieldsets by subclassing Entities e.g
https://github.com/elastic/ecs-dotnet/blob/600e7110dc5fde28c5495dc86e1d3d0f9d83adc2/tests/Elastic.CommonSchema.Tests/Serializes.cs#L121-L135
Is that sufficient?
Closing this as the linked test case should provide a way forward to introduce subclasses with extensions.