onestudio-co/flutter-bond

Support for multiple data types for a single field

Closed this issue · 1 comments

Problem Description:
When using json_serializable, I've encountered a scenario where the API can return a field (price in my case) in multiple data types (String, int, double). Currently, if we declare price as an int and the API returns a String, the fromJson method throws an exception.

Example:

{
  "id": 1,
  "name": "product",
  "price": "2.0" // or 2.0, or 2
}

Desired Behavior:
It would be great if json_serializable could handle such scenarios more gracefully, perhaps by allowing custom converters or some other mechanism to smartly convert these varying data types to a consistent one (like double).