Json Parsing issue

Subrahamanya Bhatt

New member
Joined
Jun 10, 2021
Messages
1
Programming Experience
5-10
I am Migrating the web API build in .NET framework to .NET core.
while migrating I am facing parsing issue which was handle in .NET framework while JSON parsing in API controller.
For E.g I am having a class Test with below properties
1. Public bool IsValid{get; set;}
2. public int[] YearId { get; set; }
case 1
while calling API in JSON If IsValid value is passed as null then in .NET framework it is getting parsed however not in .NET core 3.1 it is giving error as "Error converting value {null} to type 'System.Boolean'.".
Also I tried with NullValueHandling to Ignore as globally in configure service but it removes property which are null while sending the response.
case 2
while calling API in JSON If YearId value is passed as 0 then in .NET framework it is getting parsed however not in .NET core 3.1.

Can some please help me for this.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,122
Location
Chesapeake, VA
Programming Experience
10+
In your conversion process, did you swap JSON parsers from JSON.NET to the Microsoft native JSON serializer? I highly doubt that JSON.NET would change behaviors between their .NET Framework and .NET Core implementations, but I wouldn't put it past Microsoft with regards to changing the behavior.
 
Top Bottom