quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

Rename "_" to CamelCase Error

Open fabienlierville opened this issue 3 years ago • 1 comments

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(),

fabienlierville avatar Feb 01 '22 09:02 fabienlierville

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

paulisidore avatar Feb 11 '24 11:02 paulisidore