I'm not sure how to explain our goal in words, so I'll hop straight to the code.
With our current json converter settings. We get the following result when converting one of our events.
{
"PortfolioId": {
"Id": "portId"
},
"EntityId": {
"Id": "3cf7582b-3cad-4aeb-a671-0132ba97d60d"
},
"EventVersion": 1,
"OccurredOn": "2018-08-08T09:52:03.7871323+02:00",
"Id": "71fe3a2e-354a-4b19-abea-655471e96d72",
"Creator": {
"Id": "27a1d6b1-1ffa-4071-92ee-31c12bf120f0"
},
"CorrelationId": "3138dbe0-3a4d-4559-83e9-d1f3e5684ee8"
}
Our goal is to get a converted event that looks like this;
{
"PortfolioId": "portId",
"EntityId": "3cf7582b-3cad-4aeb-a671-0132ba97d60d",
"EventVersion": 1,
"OccurredOn": "2018-08-08T09:52:03.7871323+02:00",
"Id": "71fe3a2e-354a-4b19-abea-655471e96d72",
"Creator": "27a1d6b1-1ffa-4071-92ee-31c12bf120f0",
"CorrelationId": "3138dbe0-3a4d-4559-83e9-d1f3e5684ee8"
}
In the event we have an object of a certain type (i.e EntityId
, PortfolioId
) which holds the value in a property. All these Id types derive from an abstract class with the property "Id".
An event class looks like this.
public class ExampleEvent : DomainEvent
{
public PortfolioId PortfolioId { get; }
public EntityId EntityId { get;}
public ExampleEvent(
PortfolioId portfolioId,
EntityId entityId,
UserId creator, Guid correlationId) : base(creator, correlationId)
{
PortfolioId = portfolioId;
EntityId = entityId;
}
}
Does anybody have an idea how one could do this. I thought this might be possible with a custom json converter but have no idea yet on how to implement this for this case.
EDIT: I should have stated that this has to be done one many event types. And that a generic reusable solution seems to fit best in order to keep the overhead low. This mean that it is probably best if the event class itself is not altered at all. (so preferably without attributes etc)