Skip to content

Commit

Permalink
Add condition to return json as string
Browse files Browse the repository at this point in the history
A condition has been added to check if the returnType is of type 'string'. If so, the json is returned as string directly without converting. This is particularly useful to avoid unnecessary conversion when the returnType is already a string.
  • Loading branch information
sfmskywalker committed Dec 29, 2023
1 parent 704d4cd commit 3acd7f7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/modules/Elsa.Http/Parsers/JsonHttpContentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public async Task<object> ReadAsync(Stream content, Type? returnType, Cancellati

using var reader = new StreamReader(content, leaveOpen: true);
var json = await reader.ReadToEndAsync();

if(returnType == typeof(string))
return json;

if (returnType == null || returnType.IsPrimitive)
return json.ConvertTo(returnType ?? typeof(string))!;
Expand Down

0 comments on commit 3acd7f7

Please sign in to comment.