jasontaylordev / CleanArchitecture

Clean Architecture Solution Template for ASP.NET Core
MIT License
16.13k stars 3.45k forks source link

Angular 17 post data to dotnet core8. Json deserialisation of bool failed #1163

Open 1988gadocansey opened 2 months ago

1988gadocansey commented 2 months ago

MacOS ventura (M1) Dotnet 8 Angular 17

---> Microsoft.AspNetCore.Http.BadHttpRequestException: Failed to read parameter "CreateBiodataRequest command" from the request body as JSON. ---> System.Text.Json.JsonException: The JSON value could not be converted to System.Nullable`1[System.Boolean]. Path: $.residentialStatus | LineNumber: 0 | BytePositionInLine: 451. ---> System.InvalidOperationException: Cannot get the value of a token type 'String' as a boolean. at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedBoolean(JsonTokenType tokenType)

the json is below.

{ "id": 1, "firstName": "MM", "lastName": "MM", "title": "0", "previousName": "OCANSEY", "otherName": "N", "phone": "0243348522", "altPhone": "0243348522", "noOfChildren": 12, "day": "4", "year": "2005", "month": "2", "maritalStatus": "0", "gender": "0", "email": "GADOCANSEY@GMAIL.COM", "emergencyContact": "0243348522", "hometown": "CAPE COAST", "postGprs": "OCANSEY", "district": "1", "nationalIDType": "0", "nationalIDNo": "12", "regionId": "1", "nationalityId": "2", "residentialStatus": "true", "disability": "true", "disabilityType": "0", "sourceOfFinance": "OCANSEY", "religionId": "1", "denomination": "1", "referrals": "Print Media", "sponsorShipCompany": "", "sponsorShipLocation": "", "sponsorShipCompanyContact": "", "guardianName": "OCANSEY", "guardianPhone": "0243348522", "guardianOccupation": "OCANSEY", "guardianRelationship": "PARENT", "languages": [ "2" ] }

Arun25980 commented 2 months ago

the issue is with the json object. u can follow this https://stackoverflow.com/questions/75089603/system-text-json-how-to-convert-from-true-to-boolean