json_convert_content.dart 18 KB

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