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) {
9797 return DateTime .parse (input) as T ;
9898 } else if (T == String ) {
9999 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+ }
100108 }
101109 } else if (input is num ) {
102110 if (input is double && T == int ) {
@@ -105,7 +113,7 @@ T nativeFromJson<T>(dynamic input) {
105113 return input.toDouble () as T ;
106114 }
107115 }
108- throw UnimplementedError ('This type is unimplemented: ${ T . runtimeType } ' );
116+ throw UnimplementedError ('This type is unimplemented: $T ' );
109117}
110118
111119DynamicDeserializer <List <T >> listDeserializer <T >(
Original file line number Diff line number Diff line change @@ -89,6 +89,13 @@ void main() {
8989 expect (nativeFromJson <int >(42 ), equals (42 ));
9090 expect (nativeFromJson <bool >(true ), equals (true ));
9191 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);
9299 });
93100
94101 test ('nativeToJson correctly serializes null primitive types' , () {
You can’t perform that action at this time.
0 commit comments