ardalis / Result

A result abstraction that can be mapped to HTTP response codes if needed.
MIT License
866 stars 107 forks source link

Deserializing always results in a Success object. #165

Closed MischaWeerwag closed 8 months ago

MischaWeerwag commented 8 months ago

Im trying to use Ardalis Result in combination with an event bus which serializes the response type from within a command / query before returning it to the controller. This works as you would expect for Success messages, but not so much for others.

Example:

var a = JsonSerializer.Serialize(Result.NotFound("This is not found."));
// a = {"Value":null,"Status":5,"IsSuccess":false,"SuccessMessage":"","CorrelationId":"","Errors":["This is not found."],"ValidationErrors":[]}
var b = JsonSerializer.Deserialize<Result>(a);
// b =  (See Screenshot)
var c = JsonSerializer.Serialize(b);
//c = {"Value":null,"Status":0,"IsSuccess":true,"SuccessMessage":"","CorrelationId":"","Errors":[],"ValidationErrors":[]}
Screenshot 2024-02-09 at 10 13 59

This is very problematic as it looks like it is impossible to serialize / deserialise the result object.... Am I missing something or is this expected behaviour?

MischaWeerwag commented 8 months ago

166 fixes the issue!

dandcg commented 8 months ago

How long before this is resolved? I've just pulled the code - however still noticing that the Value isn't being deserialized as its generic - has anybody written some to cover this?

ardalis commented 8 months ago

Fixed by #166

ardalis commented 8 months ago

@dandcg less than a day I guess. Estimates are easy in retrospect! :)

dandcg commented 8 months ago

Chhers man nice one!