File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
packages/firebase_data_connect/firebase_data_connect Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,14 @@ T nativeFromJson<T>(dynamic input) {
97
97
return DateTime .parse (input) as T ;
98
98
} else if (T == String ) {
99
99
return input as T ;
100
+ } else if (T == int ) {
101
+ // Int64 is transmitted as String.
102
+ final value = BigInt .parse (input);
103
+ if (value.isValidInt) {
104
+ return value.toInt () as T ;
105
+ } else {
106
+ throw UnsupportedError ('BigInt ($input ) too large for Dart int' );
107
+ }
100
108
}
101
109
} else if (input is num ) {
102
110
if (input is double && T == int ) {
@@ -105,7 +113,7 @@ T nativeFromJson<T>(dynamic input) {
105
113
return input.toDouble () as T ;
106
114
}
107
115
}
108
- throw UnimplementedError ('This type is unimplemented: ${ T . runtimeType } ' );
116
+ throw UnimplementedError ('This type is unimplemented: $T ' );
109
117
}
110
118
111
119
DynamicDeserializer <List <T >> listDeserializer <T >(
Original file line number Diff line number Diff line change @@ -89,6 +89,13 @@ void main() {
89
89
expect (nativeFromJson <int >(42 ), equals (42 ));
90
90
expect (nativeFromJson <bool >(true ), equals (true ));
91
91
expect (nativeFromJson <String >('Test' ), equals ('Test' ));
92
+ expect (nativeFromJson <int >('42000000000000' ), equals (42000000000000 ));
93
+ });
94
+
95
+ test ('nativeFromJson throws UnsupportedError for bigint’s too big for int' ,
96
+ () {
97
+ expect (() => nativeFromJson <int >('42000000000000000000' ),
98
+ throwsUnsupportedError);
92
99
});
93
100
94
101
test ('nativeToJson correctly serializes null primitive types' , () {
You can’t perform that action at this time.
0 commit comments