ecs-dotnet icon indicating copy to clipboard operation
ecs-dotnet copied to clipboard

[BUG] Unable to subslass property of a property

Open andreycha opened this issue 3 years ago • 1 comments

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:

  1. I've created CustomHttpRequest which inherits HttpRequest and adds Id property. However, serialized event doesn't contain Id property because System.Text.JsonSerializer has 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; }
}
  1. I've created CustomHttp which inherits Http, adds property of type CustomHttpRequest as Request and 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

andreycha avatar Jul 25 '22 08:07 andreycha

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?

Mpdreamz avatar Sep 06 '22 19:09 Mpdreamz

Closing this as the linked test case should provide a way forward to introduce subclasses with extensions.

Mpdreamz avatar Jan 17 '23 10:01 Mpdreamz