quicktype
quicktype copied to clipboard
Rename "_" to CamelCase Error
OpenWeathermap provides an api whose certain attributes have an underscore "_", by checking the @freezed annoatin box in quickType the attribute is transformed into Camel case which causes an error when executing the dart code
Json Example for Current Weather :
{ "coord": { "lon": 139, "lat": 35 }, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01d" } ], "base": "stations", "main": { "temp": 279.22, "feels_like": 279.22, "temp_min": 278.88, "temp_max": 281.8, "pressure": 1011, "humidity": 52 }, "visibility": 10000, "wind": { "speed": 0.89, "deg": 213, "gust": 4.02 }, "clouds": { "all": 0 }, "dt": 1643702198, "sys": { "type": 2, "id": 2019346, "country": "JP", "sunrise": 1643665395, "sunset": 1643703099 }, "timezone": 32400, "id": 1851632, "name": "Shuzenji", "cod": 200 }
The problem is with "feels_like" field (Generated in WuickType with Freezed function):
` @freezed abstract class Main with _$Main { const factory Main({ double temp, double feelsLike, double tempMin, double tempMax, int pressure, int humidity, }) = _Main;
factory Main.fromJson(Map<String, dynamic> json) => _$MainFromJson(json);
} `
Error in execution : Unhandled Exception: type 'Null' is not a subtype of type 'num' in type cast
_$_Main _$$_MainFromJson(Map<String, dynamic> json) => _$_Main( temp: (json['temp'] as num).toDouble(), feelsLike: (json['feelsLike'] as num).toDouble(),
i get same issue in php target. It very difficult to correct each fields if you have lot of underscore in your json attributes.
(fr-FR): j'ai le même problème dans la cible php. Il est très difficile de corriger chaque champ si vous avez beaucoup de traits de soulignement dans vos attributs json