A lot of times we come across code where we use JSON format without actual data contract validation. eg I have a ASP.Net server side code which returns a serialized answer to Javascript client. Further this client uses some of the values within the response to make other server side calls. Though not very frequent but we do see issues where someone increased the data type on server side breaking client side in really bad way. I am looking for suggestions how can I implement a proper build time validation system to avoid such issues
Let me explain with a hypothetical example. Client makes a call to getCars(int employeeID)
==> Response object has List<CarIDs, CarNames>
. Using CarIDs
iterative calls are made from UI to getCarDetails(CarID)
. Now earlier the data type of CarID
was int
, which recently got updated to long. Javascript had a limitation to handle only upto 15 digits numbers, so on the client side any digits are de-serialization are rounded up. This caused inaccuracy in results.
Let me know if there are any suggestions on how I can implement some validation/contract upfront to get rid of such issues.
JSON模式正是为此目的而设计的,并且出色的JSON.NET库支持它。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.