@@ -237,10 +237,10 @@ class JsonSerializableGenerator
237237 {ParameterElement ctorParam}) {
238238 name = _fieldToJsonMapKey (name, field);
239239 var result = "json['$name ']" ;
240- return _writeAccessToVar (result, field.type, ctorParam: ctorParam);
240+ return _writeAccessToJsonValue (result, field.type, ctorParam: ctorParam);
241241 }
242242
243- String _writeAccessToVar (String varExpression, DartType searchType,
243+ String _writeAccessToJsonValue (String varExpression, DartType searchType,
244244 {ParameterElement ctorParam, int depth: 0 }) {
245245 if (ctorParam != null ) {
246246 searchType = ctorParam.type as InterfaceType ;
@@ -258,16 +258,16 @@ class JsonSerializableGenerator
258258 _getIterableGenericType (searchType as InterfaceType );
259259
260260 var itemVal = "v$depth " ;
261- var itemSubVal =
262- _writeAccessToVar (itemVal, iterableGenericType, depth: depth + 1 );
261+ var itemSubVal = _writeAccessToJsonValue (itemVal, iterableGenericType,
262+ depth: depth + 1 );
263263
264264 // If `itemSubVal` is the same, then we don't need to do anything fancy
265265 if (itemVal == itemSubVal) {
266266 return varExpression;
267267 }
268268
269269 var output = "($varExpression as List)?.map(($itemVal ) => "
270- "${_writeAccessToVar (itemVal , iterableGenericType , depth : depth +1 )}"
270+ "${_writeAccessToJsonValue (itemVal , iterableGenericType , depth : depth +1 )}"
271271 ")" ;
272272
273273 if (_coreListChecker.isAssignableFromType (searchType)) {
@@ -310,10 +310,10 @@ DartType _getImplementationType(DartType type, TypeChecker checker) {
310310 if (checker.isExactlyType (type)) return type;
311311
312312 if (type is InterfaceType ) {
313- var tests = [type.interfaces, type.mixins]
313+ var match = [type.interfaces, type.mixins]
314314 .expand ((e) => e)
315- .map ((type) => _getImplementationType (type, checker));
316- var match = _firstNotNull (tests );
315+ .map ((type) => _getImplementationType (type, checker))
316+ . firstWhere ((value) => value != null , orElse : () => null );
317317
318318 if (match != null ) return match;
319319
@@ -324,9 +324,6 @@ DartType _getImplementationType(DartType type, TypeChecker checker) {
324324 return null ;
325325}
326326
327- T _firstNotNull <T >(Iterable <T > values) =>
328- values.firstWhere ((value) => value != null , orElse: () => null );
329-
330327final _coreIterableChecker = const TypeChecker .fromUrl ('dart:core#Iterable' );
331328
332329final _coreListChecker = const TypeChecker .fromUrl ('dart:core#List' );
0 commit comments