-
I have a consumer that consumes messages and deserialises them into a model that looks something like this: public class Model {
public Guid Id {get; set;} = Guid.Empty();
public string Value1 {get; set;}
public int Value2 {get; set;}
} The schema contains all values but the Id, and as such the deserialiser creates the following object when consuming the message: {
"Id": null,
"Value1": "someValue",
"Value2": 2
} Is it possible to configure the deserialiser to set the id to a non null value, or have it use the value on the model it is desearilizing too? This is the code: /// <inheritdoc />
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await Parallel.ForEachAsync(_consumers, stoppingToken, async (item, token) =>
{
var consumer = item.Item1;
string topic = item.Item2;
consumer.Subscribe(topic);
while (!token.IsCancellationRequested)
{
var consumeResult = consumer.Consume(token);
//It is this object that has its Id property value set to null and not its default value.
var schema = consumeResult.Message.Value;
if (schema is null)
continue;
_ = await _dataStoreService.CreateSingleAsync(schema, token);
}
});
} And I expect something like this to be the value of my schema object: {
"Id": "00000000-0000-0000-0000-000000000000"
"Value1": "someValue",
"Value2": 2
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Sorry for any confusion this might have caused. This is not an issue at all. Default values on the object are correctly used, I just hadn't tested it properly as I assumed my issue after adding a default value to the object, was the same as before. I had some conflict on the default key serialised which was unrelated to the above. |
Beta Was this translation helpful? Give feedback.
Sorry for any confusion this might have caused. This is not an issue at all.
Default values on the object are correctly used, I just hadn't tested it properly as I assumed my issue after adding a default value to the object, was the same as before. I had some conflict on the default key serialised which was unrelated to the above.