CleanArchitecture icon indicating copy to clipboard operation
CleanArchitecture copied to clipboard

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

Open 1988gadocansey opened this issue 1 year ago • 1 comments

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": "[email protected]", "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" ] }

1988gadocansey avatar Apr 15 '24 20:04 1988gadocansey

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

Arun25980 avatar Apr 26 '24 07:04 Arun25980