I'm storing domain objects as JSON in the database. To store DDD value objects I need to create a JsonConverter
. I'm trying to create a generic value object converter in System.Text.Json
.
I have seen the following related questions in SO and EventFlow
implementation :
- Json.net how to serialize object as value
- Customise NewtonSoft.Json for Value Object serialisation
- SingleValueObjectConverter - This looks good but only applicable for
SingleValueObject
So how to create a generic value object JsonConverter
in System.Text.Json
without having a performance penalty.
Edit: To add some context, this is the entity:
public class Meeting : Entity
{
public MeetingId Id { get; private set; }
public string Title { get; private set;}
private MeetingTerm Term { get; private set;}
... // other properties
}
public class MeetingTerm : ValueObject
{
public DateTime StartDate { get; }
public DateTime EndDate { get; }
... // other properties
}
public class MeetingId : ValueObject
{
public Guid Id { get; }
... // other properties
}
I want to serialize it as:
{
"id": "unique-guid",
"title": "foo",
"startDate": "foo",
"endDate": "bar"
... // other properties
}