Skip to content

Commit e21f649

Browse files
committed
Possible null reference refactored
1 parent 817e490 commit e21f649

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Simplify.Web.Json/Model/Binding/JsonModelBinder.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System;
2+
using System.Threading.Tasks;
23
using Newtonsoft.Json;
34
using Simplify.Web.Model.Binding;
45
using Simplify.Web.Model.Validation;
@@ -38,7 +39,9 @@ public async Task BindAsync<T>(ModelBinderEventArgs<T> args)
3839
if (string.IsNullOrEmpty(args.Context.RequestBody))
3940
throw new ModelValidationException("JSON request body is null or empty");
4041

41-
args.SetModel(JsonConvert.DeserializeObject<T>(args.Context.RequestBody, _settings));
42+
var deserializedModel = JsonConvert.DeserializeObject<T>(args.Context.RequestBody, _settings) ?? throw new InvalidOperationException("Deserialized model is null");
43+
44+
args.SetModel(deserializedModel);
4245
}
4346
}
4447
}

src/Simplify.Web.Json/Simplify.Web.Json.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<RepositoryType>GIT</RepositoryType>
1515
<PackageTags>Simplify.Web JSON</PackageTags>
1616
<PackageReleaseNotes>
17-
Updates
18-
* Upgrade to Simplify.Web 4.1.1
17+
Updates
18+
* Upgrade to Simplify.Web 4.1.1
1919
</PackageReleaseNotes>
2020
<OutputPath>bin\Any CPU\$(Configuration)\</OutputPath>
2121
<DocumentationFile>bin\Any CPU\$(Configuration)\$(TargetFramework)\Simplify.Web.Json.xml</DocumentationFile>

0 commit comments

Comments
 (0)