json_convert_content.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. // ignore_for_file: non_constant_identifier_names
  2. // ignore_for_file: camel_case_types
  3. // ignore_for_file: prefer_single_quotes
  4. // This file is automatically generated. DO NOT EDIT, all your changes would be lost.
  5. import 'package:flutter/material.dart' show debugPrint;
  6. import 'package:domain/entity/auth_login_entity.dart';
  7. import 'package:domain/entity/captcha_img_entity.dart';
  8. import 'package:domain/entity/facility_book_entity.dart';
  9. import 'package:domain/entity/facility_page_entity.dart';
  10. import 'package:domain/entity/feedback_detail_entity.dart';
  11. import 'package:domain/entity/feedback_list_entity.dart';
  12. import 'package:domain/entity/form_content_entity.dart';
  13. import 'package:domain/entity/form_detail_entity.dart';
  14. import 'package:domain/entity/form_list_entity.dart';
  15. import 'package:domain/entity/form_option_entity.dart';
  16. import 'package:domain/entity/form_submitted_entity.dart';
  17. import 'package:domain/entity/form_submitted_page_entity.dart';
  18. import 'package:domain/entity/id_name_entity.dart';
  19. import 'package:domain/entity/newsfeed_comment_publish_entity.dart';
  20. import 'package:domain/entity/newsfeed_following_entity.dart';
  21. import 'package:domain/entity/newsfeed_foryou_entity.dart';
  22. import 'package:domain/entity/newsfeed_news_entity.dart';
  23. import 'package:domain/entity/property_news_entity.dart';
  24. import 'package:domain/entity/property_sale_rent_entity.dart';
  25. import 'package:domain/entity/server_time.dart';
  26. import 'package:domain/entity/user_me_entity.dart';
  27. JsonConvert jsonConvert = JsonConvert();
  28. typedef JsonConvertFunction<T> = T Function(Map<String, dynamic> json);
  29. typedef EnumConvertFunction<T> = T Function(String value);
  30. typedef ConvertExceptionHandler = void Function(Object error, StackTrace stackTrace);
  31. extension MapSafeExt<K, V> on Map<K, V> {
  32. T? getOrNull<T>(K? key) {
  33. if (!containsKey(key) || key == null) {
  34. return null;
  35. } else {
  36. return this[key] as T?;
  37. }
  38. }
  39. }
  40. class JsonConvert {
  41. static ConvertExceptionHandler? onError;
  42. JsonConvertClassCollection convertFuncMap = JsonConvertClassCollection();
  43. /// 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
  44. /// https://flutter.cn/docs/development/tools/hot-reload
  45. /// class MyApp extends StatelessWidget {
  46. /// const MyApp({Key? key})
  47. /// : super(key: key);
  48. ///
  49. /// @override
  50. /// Widget build(BuildContext context) {
  51. /// jsonConvert.reassembleConvertFuncMap();
  52. /// return MaterialApp();
  53. /// }
  54. /// }
  55. void reassembleConvertFuncMap() {
  56. bool isReleaseMode = const bool.fromEnvironment('dart.vm.product');
  57. if (!isReleaseMode) {
  58. convertFuncMap = JsonConvertClassCollection();
  59. }
  60. }
  61. T? convert<T>(dynamic value, {EnumConvertFunction? enumConvert}) {
  62. if (value == null) {
  63. return null;
  64. }
  65. if (value is T) {
  66. return value;
  67. }
  68. try {
  69. return _asT<T>(value, enumConvert: enumConvert);
  70. } catch (e, stackTrace) {
  71. debugPrint('asT<$T> $e $stackTrace');
  72. if (onError != null) {
  73. onError!(e, stackTrace);
  74. }
  75. return null;
  76. }
  77. }
  78. List<T?>? convertList<T>(List<dynamic>? value, {EnumConvertFunction? enumConvert}) {
  79. if (value == null) {
  80. return null;
  81. }
  82. try {
  83. return value.map((dynamic e) => _asT<T>(e, enumConvert: enumConvert)).toList();
  84. } catch (e, stackTrace) {
  85. debugPrint('asT<$T> $e $stackTrace');
  86. if (onError != null) {
  87. onError!(e, stackTrace);
  88. }
  89. return <T>[];
  90. }
  91. }
  92. List<T>? convertListNotNull<T>(dynamic value, {EnumConvertFunction? enumConvert}) {
  93. if (value == null) {
  94. return null;
  95. }
  96. try {
  97. return (value as List<dynamic>).map((dynamic e) => _asT<T>(e, enumConvert: enumConvert)!).toList();
  98. } catch (e, stackTrace) {
  99. debugPrint('asT<$T> $e $stackTrace');
  100. if (onError != null) {
  101. onError!(e, stackTrace);
  102. }
  103. return <T>[];
  104. }
  105. }
  106. T? _asT<T extends Object?>(dynamic value,
  107. {EnumConvertFunction? enumConvert}) {
  108. final String type = T.toString();
  109. final String valueS = value.toString();
  110. if (enumConvert != null) {
  111. return enumConvert(valueS) as T;
  112. } else if (type == "String") {
  113. return valueS as T;
  114. } else if (type == "int") {
  115. final int? intValue = int.tryParse(valueS);
  116. if (intValue == null) {
  117. return double.tryParse(valueS)?.toInt() as T?;
  118. } else {
  119. return intValue as T;
  120. }
  121. } else if (type == "double") {
  122. return double.parse(valueS) as T;
  123. } else if (type == "DateTime") {
  124. return DateTime.parse(valueS) as T;
  125. } else if (type == "bool") {
  126. if (valueS == '0' || valueS == '1') {
  127. return (valueS == '1') as T;
  128. }
  129. return (valueS == 'true') as T;
  130. } else if (type == "Map" || type.startsWith("Map<")) {
  131. return value as T;
  132. } else {
  133. if (convertFuncMap.containsKey(type)) {
  134. if (value == null) {
  135. return null;
  136. }
  137. var covertFunc = convertFuncMap[type]!;
  138. if (covertFunc is Map<String, dynamic>) {
  139. return covertFunc(value as Map<String, dynamic>) as T;
  140. } else {
  141. return covertFunc(Map<String, dynamic>.from(value)) as T;
  142. }
  143. } else {
  144. throw UnimplementedError('$type unimplemented,you can try running the app again');
  145. }
  146. }
  147. }
  148. //list is returned by type
  149. static M? _getListChildType<M>(List<Map<String, dynamic>> data) {
  150. if (<AuthLoginEntity>[] is M) {
  151. return data.map<AuthLoginEntity>((Map<String, dynamic> e) => AuthLoginEntity.fromJson(e)).toList() as M;
  152. }
  153. if (<CaptchaImgEntity>[] is M) {
  154. return data.map<CaptchaImgEntity>((Map<String, dynamic> e) => CaptchaImgEntity.fromJson(e)).toList() as M;
  155. }
  156. if (<FacilityBookEntity>[] is M) {
  157. return data.map<FacilityBookEntity>((Map<String, dynamic> e) => FacilityBookEntity.fromJson(e)).toList() as M;
  158. }
  159. if (<FacilityBookFacilityType>[] is M) {
  160. return data.map<FacilityBookFacilityType>((Map<String, dynamic> e) => FacilityBookFacilityType.fromJson(e)).toList() as M;
  161. }
  162. if (<FacilityBookFacilities>[] is M) {
  163. return data.map<FacilityBookFacilities>((Map<String, dynamic> e) => FacilityBookFacilities.fromJson(e)).toList() as M;
  164. }
  165. if (<FacilityBookFacilitiesPeriods>[] is M) {
  166. return data.map<FacilityBookFacilitiesPeriods>((Map<String, dynamic> e) => FacilityBookFacilitiesPeriods.fromJson(e)).toList() as M;
  167. }
  168. if (<FacilityPageEntity>[] is M) {
  169. return data.map<FacilityPageEntity>((Map<String, dynamic> e) => FacilityPageEntity.fromJson(e)).toList() as M;
  170. }
  171. if (<FacilityPageList>[] is M) {
  172. return data.map<FacilityPageList>((Map<String, dynamic> e) => FacilityPageList.fromJson(e)).toList() as M;
  173. }
  174. if (<FacilityPageListBooking>[] is M) {
  175. return data.map<FacilityPageListBooking>((Map<String, dynamic> e) => FacilityPageListBooking.fromJson(e)).toList() as M;
  176. }
  177. if (<FacilityPageListFacility>[] is M) {
  178. return data.map<FacilityPageListFacility>((Map<String, dynamic> e) => FacilityPageListFacility.fromJson(e)).toList() as M;
  179. }
  180. if (<FacilityPageListFacilityType>[] is M) {
  181. return data.map<FacilityPageListFacilityType>((Map<String, dynamic> e) => FacilityPageListFacilityType.fromJson(e)).toList() as M;
  182. }
  183. if (<FacilityPageListTimePeriod>[] is M) {
  184. return data.map<FacilityPageListTimePeriod>((Map<String, dynamic> e) => FacilityPageListTimePeriod.fromJson(e)).toList() as M;
  185. }
  186. if (<FacilityPageListAccount>[] is M) {
  187. return data.map<FacilityPageListAccount>((Map<String, dynamic> e) => FacilityPageListAccount.fromJson(e)).toList() as M;
  188. }
  189. if (<FeedbackDetailEntity>[] is M) {
  190. return data.map<FeedbackDetailEntity>((Map<String, dynamic> e) => FeedbackDetailEntity.fromJson(e)).toList() as M;
  191. }
  192. if (<FeedbackDetailReplies>[] is M) {
  193. return data.map<FeedbackDetailReplies>((Map<String, dynamic> e) => FeedbackDetailReplies.fromJson(e)).toList() as M;
  194. }
  195. if (<FeedbackListEntity>[] is M) {
  196. return data.map<FeedbackListEntity>((Map<String, dynamic> e) => FeedbackListEntity.fromJson(e)).toList() as M;
  197. }
  198. if (<FeedbackItemEntity>[] is M) {
  199. return data.map<FeedbackItemEntity>((Map<String, dynamic> e) => FeedbackItemEntity.fromJson(e)).toList() as M;
  200. }
  201. if (<FormContentEntity>[] is M) {
  202. return data.map<FormContentEntity>((Map<String, dynamic> e) => FormContentEntity.fromJson(e)).toList() as M;
  203. }
  204. if (<FormDetailEntity>[] is M) {
  205. return data.map<FormDetailEntity>((Map<String, dynamic> e) => FormDetailEntity.fromJson(e)).toList() as M;
  206. }
  207. if (<FormListEntity>[] is M) {
  208. return data.map<FormListEntity>((Map<String, dynamic> e) => FormListEntity.fromJson(e)).toList() as M;
  209. }
  210. if (<FormOptionEntity>[] is M) {
  211. return data.map<FormOptionEntity>((Map<String, dynamic> e) => FormOptionEntity.fromJson(e)).toList() as M;
  212. }
  213. if (<FormSubmittedEntity>[] is M) {
  214. return data.map<FormSubmittedEntity>((Map<String, dynamic> e) => FormSubmittedEntity.fromJson(e)).toList() as M;
  215. }
  216. if (<FormSubmittedEstateOnlineForm>[] is M) {
  217. return data.map<FormSubmittedEstateOnlineForm>((Map<String, dynamic> e) => FormSubmittedEstateOnlineForm.fromJson(e)).toList() as M;
  218. }
  219. if (<FormSubmittedPageEntity>[] is M) {
  220. return data.map<FormSubmittedPageEntity>((Map<String, dynamic> e) => FormSubmittedPageEntity.fromJson(e)).toList() as M;
  221. }
  222. if (<IdNameEntity>[] is M) {
  223. return data.map<IdNameEntity>((Map<String, dynamic> e) => IdNameEntity.fromJson(e)).toList() as M;
  224. }
  225. if (<NewsfeedCommentPublishEntity>[] is M) {
  226. return data.map<NewsfeedCommentPublishEntity>((Map<String, dynamic> e) => NewsfeedCommentPublishEntity.fromJson(e)).toList() as M;
  227. }
  228. if (<NewsfeedFollowingEntity>[] is M) {
  229. return data.map<NewsfeedFollowingEntity>((Map<String, dynamic> e) => NewsfeedFollowingEntity.fromJson(e)).toList() as M;
  230. }
  231. if (<NewsfeedFollowingList>[] is M) {
  232. return data.map<NewsfeedFollowingList>((Map<String, dynamic> e) => NewsfeedFollowingList.fromJson(e)).toList() as M;
  233. }
  234. if (<NewsfeedFollowingListAccount>[] is M) {
  235. return data.map<NewsfeedFollowingListAccount>((Map<String, dynamic> e) => NewsfeedFollowingListAccount.fromJson(e)).toList() as M;
  236. }
  237. if (<NewsfeedForyouEntity>[] is M) {
  238. return data.map<NewsfeedForyouEntity>((Map<String, dynamic> e) => NewsfeedForyouEntity.fromJson(e)).toList() as M;
  239. }
  240. if (<NewsfeedForyouList>[] is M) {
  241. return data.map<NewsfeedForyouList>((Map<String, dynamic> e) => NewsfeedForyouList.fromJson(e)).toList() as M;
  242. }
  243. if (<NewsfeedForyouListAccount>[] is M) {
  244. return data.map<NewsfeedForyouListAccount>((Map<String, dynamic> e) => NewsfeedForyouListAccount.fromJson(e)).toList() as M;
  245. }
  246. if (<NewsfeedNewsEntity>[] is M) {
  247. return data.map<NewsfeedNewsEntity>((Map<String, dynamic> e) => NewsfeedNewsEntity.fromJson(e)).toList() as M;
  248. }
  249. if (<NewsfeedNewsList>[] is M) {
  250. return data.map<NewsfeedNewsList>((Map<String, dynamic> e) => NewsfeedNewsList.fromJson(e)).toList() as M;
  251. }
  252. if (<NewsfeedNewsListAccount>[] is M) {
  253. return data.map<NewsfeedNewsListAccount>((Map<String, dynamic> e) => NewsfeedNewsListAccount.fromJson(e)).toList() as M;
  254. }
  255. if (<PropertyNewsEntity>[] is M) {
  256. return data.map<PropertyNewsEntity>((Map<String, dynamic> e) => PropertyNewsEntity.fromJson(e)).toList() as M;
  257. }
  258. if (<PropertyNewsList>[] is M) {
  259. return data.map<PropertyNewsList>((Map<String, dynamic> e) => PropertyNewsList.fromJson(e)).toList() as M;
  260. }
  261. if (<PropertySaleRentEntity>[] is M) {
  262. return data.map<PropertySaleRentEntity>((Map<String, dynamic> e) => PropertySaleRentEntity.fromJson(e)).toList() as M;
  263. }
  264. if (<PropertySaleRentList>[] is M) {
  265. return data.map<PropertySaleRentList>((Map<String, dynamic> e) => PropertySaleRentList.fromJson(e)).toList() as M;
  266. }
  267. if (<ServerTime>[] is M) {
  268. return data.map<ServerTime>((Map<String, dynamic> e) => ServerTime.fromJson(e)).toList() as M;
  269. }
  270. if (<UserMeEntity>[] is M) {
  271. return data.map<UserMeEntity>((Map<String, dynamic> e) => UserMeEntity.fromJson(e)).toList() as M;
  272. }
  273. if (<UserMeHouseholds>[] is M) {
  274. return data.map<UserMeHouseholds>((Map<String, dynamic> e) => UserMeHouseholds.fromJson(e)).toList() as M;
  275. }
  276. if (<UserMeEstates>[] is M) {
  277. return data.map<UserMeEstates>((Map<String, dynamic> e) => UserMeEstates.fromJson(e)).toList() as M;
  278. }
  279. if (<UserMeEstatesAccounts>[] is M) {
  280. return data.map<UserMeEstatesAccounts>((Map<String, dynamic> e) => UserMeEstatesAccounts.fromJson(e)).toList() as M;
  281. }
  282. if (<UserMeEstatesAccountsUnit>[] is M) {
  283. return data.map<UserMeEstatesAccountsUnit>((Map<String, dynamic> e) => UserMeEstatesAccountsUnit.fromJson(e)).toList() as M;
  284. }
  285. if (<UserMeDefaultUnit>[] is M) {
  286. return data.map<UserMeDefaultUnit>((Map<String, dynamic> e) => UserMeDefaultUnit.fromJson(e)).toList() as M;
  287. }
  288. if (<UserMeInformation>[] is M) {
  289. return data.map<UserMeInformation>((Map<String, dynamic> e) => UserMeInformation.fromJson(e)).toList() as M;
  290. }
  291. debugPrint("$M not found");
  292. return null;
  293. }
  294. static M? fromJsonAsT<M>(dynamic json) {
  295. if (json is M) {
  296. return json;
  297. }
  298. if (json is List) {
  299. return _getListChildType<M>(json.map((dynamic e) => e as Map<String, dynamic>).toList());
  300. } else {
  301. return jsonConvert.convert<M>(json);
  302. }
  303. }
  304. }
  305. class JsonConvertClassCollection {
  306. Map<String, JsonConvertFunction> convertFuncMap = {
  307. (AuthLoginEntity).toString(): AuthLoginEntity.fromJson,
  308. (CaptchaImgEntity).toString(): CaptchaImgEntity.fromJson,
  309. (FacilityBookEntity).toString(): FacilityBookEntity.fromJson,
  310. (FacilityBookFacilityType).toString(): FacilityBookFacilityType.fromJson,
  311. (FacilityBookFacilities).toString(): FacilityBookFacilities.fromJson,
  312. (FacilityBookFacilitiesPeriods).toString(): FacilityBookFacilitiesPeriods.fromJson,
  313. (FacilityPageEntity).toString(): FacilityPageEntity.fromJson,
  314. (FacilityPageList).toString(): FacilityPageList.fromJson,
  315. (FacilityPageListBooking).toString(): FacilityPageListBooking.fromJson,
  316. (FacilityPageListFacility).toString(): FacilityPageListFacility.fromJson,
  317. (FacilityPageListFacilityType).toString(): FacilityPageListFacilityType.fromJson,
  318. (FacilityPageListTimePeriod).toString(): FacilityPageListTimePeriod.fromJson,
  319. (FacilityPageListAccount).toString(): FacilityPageListAccount.fromJson,
  320. (FeedbackDetailEntity).toString(): FeedbackDetailEntity.fromJson,
  321. (FeedbackDetailReplies).toString(): FeedbackDetailReplies.fromJson,
  322. (FeedbackListEntity).toString(): FeedbackListEntity.fromJson,
  323. (FeedbackItemEntity).toString(): FeedbackItemEntity.fromJson,
  324. (FormContentEntity).toString(): FormContentEntity.fromJson,
  325. (FormDetailEntity).toString(): FormDetailEntity.fromJson,
  326. (FormListEntity).toString(): FormListEntity.fromJson,
  327. (FormOptionEntity).toString(): FormOptionEntity.fromJson,
  328. (FormSubmittedEntity).toString(): FormSubmittedEntity.fromJson,
  329. (FormSubmittedEstateOnlineForm).toString(): FormSubmittedEstateOnlineForm.fromJson,
  330. (FormSubmittedPageEntity).toString(): FormSubmittedPageEntity.fromJson,
  331. (IdNameEntity).toString(): IdNameEntity.fromJson,
  332. (NewsfeedCommentPublishEntity).toString(): NewsfeedCommentPublishEntity.fromJson,
  333. (NewsfeedFollowingEntity).toString(): NewsfeedFollowingEntity.fromJson,
  334. (NewsfeedFollowingList).toString(): NewsfeedFollowingList.fromJson,
  335. (NewsfeedFollowingListAccount).toString(): NewsfeedFollowingListAccount.fromJson,
  336. (NewsfeedForyouEntity).toString(): NewsfeedForyouEntity.fromJson,
  337. (NewsfeedForyouList).toString(): NewsfeedForyouList.fromJson,
  338. (NewsfeedForyouListAccount).toString(): NewsfeedForyouListAccount.fromJson,
  339. (NewsfeedNewsEntity).toString(): NewsfeedNewsEntity.fromJson,
  340. (NewsfeedNewsList).toString(): NewsfeedNewsList.fromJson,
  341. (NewsfeedNewsListAccount).toString(): NewsfeedNewsListAccount.fromJson,
  342. (PropertyNewsEntity).toString(): PropertyNewsEntity.fromJson,
  343. (PropertyNewsList).toString(): PropertyNewsList.fromJson,
  344. (PropertySaleRentEntity).toString(): PropertySaleRentEntity.fromJson,
  345. (PropertySaleRentList).toString(): PropertySaleRentList.fromJson,
  346. (ServerTime).toString(): ServerTime.fromJson,
  347. (UserMeEntity).toString(): UserMeEntity.fromJson,
  348. (UserMeHouseholds).toString(): UserMeHouseholds.fromJson,
  349. (UserMeEstates).toString(): UserMeEstates.fromJson,
  350. (UserMeEstatesAccounts).toString(): UserMeEstatesAccounts.fromJson,
  351. (UserMeEstatesAccountsUnit).toString(): UserMeEstatesAccountsUnit.fromJson,
  352. (UserMeDefaultUnit).toString(): UserMeDefaultUnit.fromJson,
  353. (UserMeInformation).toString(): UserMeInformation.fromJson,
  354. };
  355. bool containsKey(String type) {
  356. return convertFuncMap.containsKey(type);
  357. }
  358. JsonConvertFunction? operator [](String key) {
  359. return convertFuncMap[key];
  360. }
  361. }