Skip to content

Commit c243b6f

Browse files
committed
Check for null before parsing toDouble
1 parent 56ed53d commit c243b6f

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

modules/swagger-codegen/src/main/resources/dart/class.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class {{classname}} {
2929
{{/isListContainer}}
3030
{{^isListContainer}}
3131
{{#isDouble}}
32-
json['{{baseName}}'].toDouble()
32+
json['{{baseName}}'] == null ? null : json['{{baseName}}'].toDouble()
3333
{{/isDouble}}
3434
{{^isDouble}}
3535
json['{{baseName}}']

samples/client/petstore/dart/flutter_petstore/swagger/lib/model/amount.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Amount {
1717
Amount.fromJson(Map<String, dynamic> json) {
1818
if (json == null) return;
1919
value =
20-
json['value'].toDouble()
20+
json['value'] == null ? null : json['value'].toDouble()
2121
;
2222
currency =
2323

samples/client/petstore/dart/swagger-browser-client/lib/model/amount.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Amount {
1717
Amount.fromJson(Map<String, dynamic> json) {
1818
if (json == null) return;
1919
value =
20-
json['value'].toDouble()
20+
json['value'] == null ? null : json['value'].toDouble()
2121
;
2222
currency =
2323

samples/client/petstore/dart/swagger/lib/model/amount.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Amount {
1717
Amount.fromJson(Map<String, dynamic> json) {
1818
if (json == null) return;
1919
value =
20-
json['value'].toDouble()
20+
json['value'] == null ? null : json['value'].toDouble()
2121
;
2222
currency =
2323

0 commit comments

Comments
 (0)