// ignore_for_file: non_constant_identifier_names // ignore_for_file: camel_case_types // ignore_for_file: prefer_single_quotes // This file is automatically generated. DO NOT EDIT, all your changes would be lost. import 'package:flutter/material.dart' show debugPrint; import 'package:domain/entity/auth_login_entity.dart'; import 'package:domain/entity/captcha_img_entity.dart'; import 'package:domain/entity/feedback_detail_entity.dart'; import 'package:domain/entity/feedback_list_entity.dart'; import 'package:domain/entity/id_name_entity.dart'; import 'package:domain/entity/newsfeed_comment_publish_entity.dart'; import 'package:domain/entity/newsfeed_following_entity.dart'; import 'package:domain/entity/newsfeed_foryou_entity.dart'; import 'package:domain/entity/newsfeed_news_entity.dart'; import 'package:domain/entity/notice_board_announ_entity.dart'; import 'package:domain/entity/notice_board_documents_entity.dart'; import 'package:domain/entity/notice_board_event_entity.dart'; import 'package:domain/entity/property_news_entity.dart'; import 'package:domain/entity/property_sale_rent_entity.dart'; import 'package:domain/entity/server_time.dart'; import 'package:domain/entity/user_me_entity.dart'; JsonConvert jsonConvert = JsonConvert(); typedef JsonConvertFunction = T Function(Map json); typedef EnumConvertFunction = T Function(String value); typedef ConvertExceptionHandler = void Function(Object error, StackTrace stackTrace); extension MapSafeExt on Map { T? getOrNull(K? key) { if (!containsKey(key) || key == null) { return null; } else { return this[key] as T?; } } } class JsonConvert { static ConvertExceptionHandler? onError; JsonConvertClassCollection convertFuncMap = JsonConvertClassCollection(); /// When you are in the development, to generate a new model class, hot-reload doesn't find new generation model class, you can build on MaterialApp method called jsonConvert. ReassembleConvertFuncMap (); This method only works in a development environment /// https://flutter.cn/docs/development/tools/hot-reload /// class MyApp extends StatelessWidget { /// const MyApp({Key? key}) /// : super(key: key); /// /// @override /// Widget build(BuildContext context) { /// jsonConvert.reassembleConvertFuncMap(); /// return MaterialApp(); /// } /// } void reassembleConvertFuncMap() { bool isReleaseMode = const bool.fromEnvironment('dart.vm.product'); if (!isReleaseMode) { convertFuncMap = JsonConvertClassCollection(); } } T? convert(dynamic value, {EnumConvertFunction? enumConvert}) { if (value == null) { return null; } if (value is T) { return value; } try { return _asT(value, enumConvert: enumConvert); } catch (e, stackTrace) { debugPrint('asT<$T> $e $stackTrace'); if (onError != null) { onError!(e, stackTrace); } return null; } } List? convertList(List? value, {EnumConvertFunction? enumConvert}) { if (value == null) { return null; } try { return value.map((dynamic e) => _asT(e, enumConvert: enumConvert)) .toList(); } catch (e, stackTrace) { debugPrint('asT<$T> $e $stackTrace'); if (onError != null) { onError!(e, stackTrace); } return []; } } List? convertListNotNull(dynamic value, {EnumConvertFunction? enumConvert}) { if (value == null) { return null; } try { return (value as List).map((dynamic e) => _asT(e, enumConvert: enumConvert)!).toList(); } catch (e, stackTrace) { debugPrint('asT<$T> $e $stackTrace'); if (onError != null) { onError!(e, stackTrace); } return []; } } T? _asT(dynamic value, {EnumConvertFunction? enumConvert}) { final String type = T.toString(); final String valueS = value.toString(); if (enumConvert != null) { return enumConvert(valueS) as T; } else if (type == "String") { return valueS as T; } else if (type == "int") { final int? intValue = int.tryParse(valueS); if (intValue == null) { return double.tryParse(valueS)?.toInt() as T?; } else { return intValue as T; } } else if (type == "double") { return double.parse(valueS) as T; } else if (type == "DateTime") { return DateTime.parse(valueS) as T; } else if (type == "bool") { if (valueS == '0' || valueS == '1') { return (valueS == '1') as T; } return (valueS == 'true') as T; } else if (type == "Map" || type.startsWith("Map<")) { return value as T; } else { if (convertFuncMap.containsKey(type)) { if (value == null) { return null; } var covertFunc = convertFuncMap[type]!; if (covertFunc is Map) { return covertFunc(value as Map) as T; } else { return covertFunc(Map.from(value)) as T; } } else { throw UnimplementedError( '$type unimplemented,you can try running the app again'); } } } //list is returned by type static M? _getListChildType(List> data) { if ([] is M) { return data.map((Map e) => AuthLoginEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => CaptchaImgEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => FeedbackDetailEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => FeedbackDetailReplies.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => FeedbackListEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => FeedbackItemEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => IdNameEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NewsfeedCommentPublishEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NewsfeedFollowingEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NewsfeedFollowingList.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NewsfeedFollowingListAccount.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NewsfeedForyouEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NewsfeedForyouList.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NewsfeedForyouListAccount.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NewsfeedNewsEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NewsfeedNewsList.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NewsfeedNewsListAccount.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NoticeBoardAnnounEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NoticeBoardDocumentsEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => NoticeBoardEventEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => PropertyNewsEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => PropertyNewsList.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => PropertySaleRentEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => PropertySaleRentList.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => ServerTime.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => UserMeEntity.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => UserMeHouseholds.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => UserMeEstates.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => UserMeEstatesAccounts.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => UserMeEstatesAccountsUnit.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => UserMeDefaultUnit.fromJson(e)).toList() as M; } if ([] is M) { return data.map((Map e) => UserMeInformation.fromJson(e)).toList() as M; } debugPrint("$M not found"); return null; } static M? fromJsonAsT(dynamic json) { if (json is M) { return json; } if (json is List) { return _getListChildType( json.map((dynamic e) => e as Map).toList()); } else { return jsonConvert.convert(json); } } } class JsonConvertClassCollection { Map convertFuncMap = { (AuthLoginEntity).toString(): AuthLoginEntity.fromJson, (CaptchaImgEntity).toString(): CaptchaImgEntity.fromJson, (FeedbackDetailEntity).toString(): FeedbackDetailEntity.fromJson, (FeedbackDetailReplies).toString(): FeedbackDetailReplies.fromJson, (FeedbackListEntity).toString(): FeedbackListEntity.fromJson, (FeedbackItemEntity).toString(): FeedbackItemEntity.fromJson, (IdNameEntity).toString(): IdNameEntity.fromJson, (NewsfeedCommentPublishEntity).toString(): NewsfeedCommentPublishEntity .fromJson, (NewsfeedFollowingEntity).toString(): NewsfeedFollowingEntity.fromJson, (NewsfeedFollowingList).toString(): NewsfeedFollowingList.fromJson, (NewsfeedFollowingListAccount).toString(): NewsfeedFollowingListAccount .fromJson, (NewsfeedForyouEntity).toString(): NewsfeedForyouEntity.fromJson, (NewsfeedForyouList).toString(): NewsfeedForyouList.fromJson, (NewsfeedForyouListAccount).toString(): NewsfeedForyouListAccount.fromJson, (NewsfeedNewsEntity).toString(): NewsfeedNewsEntity.fromJson, (NewsfeedNewsList).toString(): NewsfeedNewsList.fromJson, (NewsfeedNewsListAccount).toString(): NewsfeedNewsListAccount.fromJson, (NoticeBoardAnnounEntity).toString(): NoticeBoardAnnounEntity.fromJson, (NoticeBoardDocumentsEntity).toString(): NoticeBoardDocumentsEntity .fromJson, (NoticeBoardEventEntity).toString(): NoticeBoardEventEntity.fromJson, (PropertyNewsEntity).toString(): PropertyNewsEntity.fromJson, (PropertyNewsList).toString(): PropertyNewsList.fromJson, (PropertySaleRentEntity).toString(): PropertySaleRentEntity.fromJson, (PropertySaleRentList).toString(): PropertySaleRentList.fromJson, (ServerTime).toString(): ServerTime.fromJson, (UserMeEntity).toString(): UserMeEntity.fromJson, (UserMeHouseholds).toString(): UserMeHouseholds.fromJson, (UserMeEstates).toString(): UserMeEstates.fromJson, (UserMeEstatesAccounts).toString(): UserMeEstatesAccounts.fromJson, (UserMeEstatesAccountsUnit).toString(): UserMeEstatesAccountsUnit.fromJson, (UserMeDefaultUnit).toString(): UserMeDefaultUnit.fromJson, (UserMeInformation).toString(): UserMeInformation.fromJson, }; bool containsKey(String type) { return convertFuncMap.containsKey(type); } JsonConvertFunction? operator [](String key) { return convertFuncMap[key]; } }