json_convert_content.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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_entity.dart';
  17. import 'package:domain/entity/id_name_entity.dart';
  18. import 'package:domain/entity/newsfeed_comment_publish_entity.dart';
  19. import 'package:domain/entity/newsfeed_detail_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,
  79. {EnumConvertFunction? enumConvert}) {
  80. if (value == null) {
  81. return null;
  82. }
  83. try {
  84. return value.map((dynamic e) => _asT<T>(e, enumConvert: enumConvert))
  85. .toList();
  86. } catch (e, stackTrace) {
  87. debugPrint('asT<$T> $e $stackTrace');
  88. if (onError != null) {
  89. onError!(e, stackTrace);
  90. }
  91. return <T>[];
  92. }
  93. }
  94. List<T>? convertListNotNull<T>(dynamic value,
  95. {EnumConvertFunction? enumConvert}) {
  96. if (value == null) {
  97. return null;
  98. }
  99. try {
  100. return (value as List<dynamic>).map((dynamic e) =>
  101. _asT<T>(e, enumConvert: enumConvert)!).toList();
  102. } catch (e, stackTrace) {
  103. debugPrint('asT<$T> $e $stackTrace');
  104. if (onError != null) {
  105. onError!(e, stackTrace);
  106. }
  107. return <T>[];
  108. }
  109. }
  110. T? _asT<T extends Object?>(dynamic value,
  111. {EnumConvertFunction? enumConvert}) {
  112. final String type = T.toString();
  113. final String valueS = value.toString();
  114. if (enumConvert != null) {
  115. return enumConvert(valueS) as T;
  116. } else if (type == "String") {
  117. return valueS as T;
  118. } else if (type == "int") {
  119. final int? intValue = int.tryParse(valueS);
  120. if (intValue == null) {
  121. return double.tryParse(valueS)?.toInt() as T?;
  122. } else {
  123. return intValue as T;
  124. }
  125. } else if (type == "double") {
  126. return double.parse(valueS) as T;
  127. } else if (type == "DateTime") {
  128. return DateTime.parse(valueS) as T;
  129. } else if (type == "bool") {
  130. if (valueS == '0' || valueS == '1') {
  131. return (valueS == '1') as T;
  132. }
  133. return (valueS == 'true') as T;
  134. } else if (type == "Map" || type.startsWith("Map<")) {
  135. return value as T;
  136. } else {
  137. if (convertFuncMap.containsKey(type)) {
  138. if (value == null) {
  139. return null;
  140. }
  141. var covertFunc = convertFuncMap[type]!;
  142. if (covertFunc is Map<String, dynamic>) {
  143. return covertFunc(value as Map<String, dynamic>) as T;
  144. } else {
  145. return covertFunc(Map<String, dynamic>.from(value)) as T;
  146. }
  147. } else {
  148. throw UnimplementedError(
  149. '$type unimplemented,you can try running the app again');
  150. }
  151. }
  152. }
  153. //list is returned by type
  154. static M? _getListChildType<M>(List<Map<String, dynamic>> data) {
  155. if (<AuthLoginEntity>[] is M) {
  156. return data.map<AuthLoginEntity>((Map<String, dynamic> e) =>
  157. AuthLoginEntity.fromJson(e)).toList() as M;
  158. }
  159. if (<CaptchaImgEntity>[] is M) {
  160. return data.map<CaptchaImgEntity>((Map<String, dynamic> e) =>
  161. CaptchaImgEntity.fromJson(e)).toList() as M;
  162. }
  163. if (<FeedbackDetailEntity>[] is M) {
  164. return data.map<FeedbackDetailEntity>((Map<String, dynamic> e) =>
  165. FeedbackDetailEntity.fromJson(e)).toList() as M;
  166. }
  167. if (<FeedbackDetailReplies>[] is M) {
  168. return data.map<FeedbackDetailReplies>((Map<String, dynamic> e) =>
  169. FeedbackDetailReplies.fromJson(e)).toList() as M;
  170. }
  171. if (<FeedbackListEntity>[] is M) {
  172. return data.map<FeedbackListEntity>((Map<String, dynamic> e) =>
  173. FeedbackListEntity.fromJson(e)).toList() as M;
  174. }
  175. if (<FeedbackItemEntity>[] is M) {
  176. return data.map<FeedbackItemEntity>((Map<String, dynamic> e) =>
  177. FeedbackItemEntity.fromJson(e)).toList() as M;
  178. }
  179. if (<FormContentEntity>[] is M) {
  180. return data.map<FormContentEntity>((Map<String, dynamic> e) =>
  181. FormContentEntity.fromJson(e)).toList() as M;
  182. }
  183. if (<FormDetailEntity>[] is M) {
  184. return data.map<FormDetailEntity>((Map<String, dynamic> e) =>
  185. FormDetailEntity.fromJson(e)).toList() as M;
  186. }
  187. if (<FormListEntity>[] is M) {
  188. return data.map<FormListEntity>((Map<String, dynamic> e) =>
  189. FormListEntity.fromJson(e)).toList() as M;
  190. }
  191. if (<FormOptionEntity>[] is M) {
  192. return data.map<FormOptionEntity>((Map<String, dynamic> e) =>
  193. FormOptionEntity.fromJson(e)).toList() as M;
  194. }
  195. if (<FormSubmittedEntity>[] is M) {
  196. return data.map<FormSubmittedEntity>((Map<String, dynamic> e) =>
  197. FormSubmittedEntity.fromJson(e)).toList() as M;
  198. }
  199. if (<FormSubmittedEstateOnlineForm>[] is M) {
  200. return data.map<FormSubmittedEstateOnlineForm>((Map<String, dynamic> e) =>
  201. FormSubmittedEstateOnlineForm.fromJson(e)).toList() as M;
  202. }
  203. if (<FormSubmittedPageEntity>[] is M) {
  204. return data.map<FormSubmittedPageEntity>((Map<String, dynamic> e) =>
  205. FormSubmittedPageEntity.fromJson(e)).toList() as M;
  206. }
  207. if (<GarageSaleRentEntity>[] is M) {
  208. return data.map<GarageSaleRentEntity>((Map<String, dynamic> e) =>
  209. GarageSaleRentEntity.fromJson(e)).toList() as M;
  210. }
  211. if (<GarageSaleRentAccount>[] is M) {
  212. return data.map<GarageSaleRentAccount>((Map<String, dynamic> e) =>
  213. GarageSaleRentAccount.fromJson(e)).toList() as M;
  214. }
  215. if (<IdNameEntity>[] is M) {
  216. return data.map<IdNameEntity>((Map<String, dynamic> e) =>
  217. IdNameEntity.fromJson(e)).toList() as M;
  218. }
  219. if (<NewsfeedCommentPublishEntity>[] is M) {
  220. return data.map<NewsfeedCommentPublishEntity>((Map<String, dynamic> e) =>
  221. NewsfeedCommentPublishEntity.fromJson(e)).toList() as M;
  222. }
  223. if (<NewsfeedDetailEntity>[] is M) {
  224. return data.map<NewsfeedDetailEntity>((Map<String, dynamic> e) =>
  225. NewsfeedDetailEntity.fromJson(e)).toList() as M;
  226. }
  227. if (<NewsfeedDetailAccount>[] is M) {
  228. return data.map<NewsfeedDetailAccount>((Map<String, dynamic> e) =>
  229. NewsfeedDetailAccount.fromJson(e)).toList() as M;
  230. }
  231. if (<NewsfeedDetailComments>[] is M) {
  232. return data.map<NewsfeedDetailComments>((Map<String, dynamic> e) =>
  233. NewsfeedDetailComments.fromJson(e)).toList() as M;
  234. }
  235. if (<NewsfeedDetailCommentsAccount>[] is M) {
  236. return data.map<NewsfeedDetailCommentsAccount>((Map<String, dynamic> e) =>
  237. NewsfeedDetailCommentsAccount.fromJson(e)).toList() as M;
  238. }
  239. if (<NewsfeedDetailCommentsToAccount>[] is M) {
  240. return data.map<NewsfeedDetailCommentsToAccount>((
  241. Map<String, dynamic> e) =>
  242. NewsfeedDetailCommentsToAccount.fromJson(e)).toList() as M;
  243. }
  244. if (<NewsfeedFollowingEntity>[] is M) {
  245. return data.map<NewsfeedFollowingEntity>((Map<String, dynamic> e) =>
  246. NewsfeedFollowingEntity.fromJson(e)).toList() as M;
  247. }
  248. if (<NewsfeedFollowingList>[] is M) {
  249. return data.map<NewsfeedFollowingList>((Map<String, dynamic> e) =>
  250. NewsfeedFollowingList.fromJson(e)).toList() as M;
  251. }
  252. if (<NewsfeedFollowingListAccount>[] is M) {
  253. return data.map<NewsfeedFollowingListAccount>((Map<String, dynamic> e) =>
  254. NewsfeedFollowingListAccount.fromJson(e)).toList() as M;
  255. }
  256. if (<NewsfeedForyouEntity>[] is M) {
  257. return data.map<NewsfeedForyouEntity>((Map<String, dynamic> e) =>
  258. NewsfeedForyouEntity.fromJson(e)).toList() as M;
  259. }
  260. if (<NewsfeedForyouList>[] is M) {
  261. return data.map<NewsfeedForyouList>((Map<String, dynamic> e) =>
  262. NewsfeedForyouList.fromJson(e)).toList() as M;
  263. }
  264. if (<NewsfeedForyouListAccount>[] is M) {
  265. return data.map<NewsfeedForyouListAccount>((Map<String, dynamic> e) =>
  266. NewsfeedForyouListAccount.fromJson(e)).toList() as M;
  267. }
  268. if (<NewsfeedNewsEntity>[] is M) {
  269. return data.map<NewsfeedNewsEntity>((Map<String, dynamic> e) =>
  270. NewsfeedNewsEntity.fromJson(e)).toList() as M;
  271. }
  272. if (<NewsfeedNewsList>[] is M) {
  273. return data.map<NewsfeedNewsList>((Map<String, dynamic> e) =>
  274. NewsfeedNewsList.fromJson(e)).toList() as M;
  275. }
  276. if (<NewsfeedNewsListAccount>[] is M) {
  277. return data.map<NewsfeedNewsListAccount>((Map<String, dynamic> e) =>
  278. NewsfeedNewsListAccount.fromJson(e)).toList() as M;
  279. }
  280. if (<PropertyNewsEntity>[] is M) {
  281. return data.map<PropertyNewsEntity>((Map<String, dynamic> e) =>
  282. PropertyNewsEntity.fromJson(e)).toList() as M;
  283. }
  284. if (<PropertyNewsList>[] is M) {
  285. return data.map<PropertyNewsList>((Map<String, dynamic> e) =>
  286. PropertyNewsList.fromJson(e)).toList() as M;
  287. }
  288. if (<PropertySaleRentEntity>[] is M) {
  289. return data.map<PropertySaleRentEntity>((Map<String, dynamic> e) =>
  290. PropertySaleRentEntity.fromJson(e)).toList() as M;
  291. }
  292. if (<PropertySaleRentList>[] is M) {
  293. return data.map<PropertySaleRentList>((Map<String, dynamic> e) =>
  294. PropertySaleRentList.fromJson(e)).toList() as M;
  295. }
  296. if (<ServerTime>[] is M) {
  297. return data.map<ServerTime>((Map<String, dynamic> e) =>
  298. ServerTime.fromJson(e)).toList() as M;
  299. }
  300. if (<UserMeEntity>[] is M) {
  301. return data.map<UserMeEntity>((Map<String, dynamic> e) =>
  302. UserMeEntity.fromJson(e)).toList() as M;
  303. }
  304. if (<UserMeHouseholds>[] is M) {
  305. return data.map<UserMeHouseholds>((Map<String, dynamic> e) =>
  306. UserMeHouseholds.fromJson(e)).toList() as M;
  307. }
  308. if (<UserMeEstates>[] is M) {
  309. return data.map<UserMeEstates>((Map<String, dynamic> e) =>
  310. UserMeEstates.fromJson(e)).toList() as M;
  311. }
  312. if (<UserMeEstatesAccounts>[] is M) {
  313. return data.map<UserMeEstatesAccounts>((Map<String, dynamic> e) =>
  314. UserMeEstatesAccounts.fromJson(e)).toList() as M;
  315. }
  316. if (<UserMeEstatesAccountsUnit>[] is M) {
  317. return data.map<UserMeEstatesAccountsUnit>((Map<String, dynamic> e) =>
  318. UserMeEstatesAccountsUnit.fromJson(e)).toList() as M;
  319. }
  320. if (<UserMeDefaultUnit>[] is M) {
  321. return data.map<UserMeDefaultUnit>((Map<String, dynamic> e) =>
  322. UserMeDefaultUnit.fromJson(e)).toList() as M;
  323. }
  324. if (<UserMeInformation>[] is M) {
  325. return data.map<UserMeInformation>((Map<String, dynamic> e) =>
  326. UserMeInformation.fromJson(e)).toList() as M;
  327. }
  328. debugPrint("$M not found");
  329. return null;
  330. }
  331. static M? fromJsonAsT<M>(dynamic json) {
  332. if (json is M) {
  333. return json;
  334. }
  335. if (json is List) {
  336. return _getListChildType<M>(
  337. json.map((dynamic e) => e as Map<String, dynamic>).toList());
  338. } else {
  339. return jsonConvert.convert<M>(json);
  340. }
  341. }
  342. }
  343. class JsonConvertClassCollection {
  344. Map<String, JsonConvertFunction> convertFuncMap = {
  345. (AuthLoginEntity).toString(): AuthLoginEntity.fromJson,
  346. (CaptchaImgEntity).toString(): CaptchaImgEntity.fromJson,
  347. (FeedbackDetailEntity).toString(): FeedbackDetailEntity.fromJson,
  348. (FeedbackDetailReplies).toString(): FeedbackDetailReplies.fromJson,
  349. (FeedbackListEntity).toString(): FeedbackListEntity.fromJson,
  350. (FeedbackItemEntity).toString(): FeedbackItemEntity.fromJson,
  351. (FormContentEntity).toString(): FormContentEntity.fromJson,
  352. (FormDetailEntity).toString(): FormDetailEntity.fromJson,
  353. (FormListEntity).toString(): FormListEntity.fromJson,
  354. (FormOptionEntity).toString(): FormOptionEntity.fromJson,
  355. (FormSubmittedEntity).toString(): FormSubmittedEntity.fromJson,
  356. (FormSubmittedEstateOnlineForm).toString(): FormSubmittedEstateOnlineForm
  357. .fromJson,
  358. (FormSubmittedPageEntity).toString(): FormSubmittedPageEntity.fromJson,
  359. (GarageSaleRentEntity).toString(): GarageSaleRentEntity.fromJson,
  360. (GarageSaleRentAccount).toString(): GarageSaleRentAccount.fromJson,
  361. (IdNameEntity).toString(): IdNameEntity.fromJson,
  362. (NewsfeedCommentPublishEntity).toString(): NewsfeedCommentPublishEntity
  363. .fromJson,
  364. (NewsfeedDetailEntity).toString(): NewsfeedDetailEntity.fromJson,
  365. (NewsfeedDetailAccount).toString(): NewsfeedDetailAccount.fromJson,
  366. (NewsfeedDetailComments).toString(): NewsfeedDetailComments.fromJson,
  367. (NewsfeedDetailCommentsAccount).toString(): NewsfeedDetailCommentsAccount
  368. .fromJson,
  369. (NewsfeedDetailCommentsToAccount)
  370. .toString(): NewsfeedDetailCommentsToAccount.fromJson,
  371. (NewsfeedFollowingEntity).toString(): NewsfeedFollowingEntity.fromJson,
  372. (NewsfeedFollowingList).toString(): NewsfeedFollowingList.fromJson,
  373. (NewsfeedFollowingListAccount).toString(): NewsfeedFollowingListAccount
  374. .fromJson,
  375. (NewsfeedForyouEntity).toString(): NewsfeedForyouEntity.fromJson,
  376. (NewsfeedForyouList).toString(): NewsfeedForyouList.fromJson,
  377. (NewsfeedForyouListAccount).toString(): NewsfeedForyouListAccount.fromJson,
  378. (NewsfeedNewsEntity).toString(): NewsfeedNewsEntity.fromJson,
  379. (NewsfeedNewsList).toString(): NewsfeedNewsList.fromJson,
  380. (NewsfeedNewsListAccount).toString(): NewsfeedNewsListAccount.fromJson,
  381. (PropertyNewsEntity).toString(): PropertyNewsEntity.fromJson,
  382. (PropertyNewsList).toString(): PropertyNewsList.fromJson,
  383. (PropertySaleRentEntity).toString(): PropertySaleRentEntity.fromJson,
  384. (PropertySaleRentList).toString(): PropertySaleRentList.fromJson,
  385. (ServerTime).toString(): ServerTime.fromJson,
  386. (UserMeEntity).toString(): UserMeEntity.fromJson,
  387. (UserMeHouseholds).toString(): UserMeHouseholds.fromJson,
  388. (UserMeEstates).toString(): UserMeEstates.fromJson,
  389. (UserMeEstatesAccounts).toString(): UserMeEstatesAccounts.fromJson,
  390. (UserMeEstatesAccountsUnit).toString(): UserMeEstatesAccountsUnit.fromJson,
  391. (UserMeDefaultUnit).toString(): UserMeDefaultUnit.fromJson,
  392. (UserMeInformation).toString(): UserMeInformation.fromJson,
  393. };
  394. bool containsKey(String type) {
  395. return convertFuncMap.containsKey(type);
  396. }
  397. JsonConvertFunction? operator [](String key) {
  398. return convertFuncMap[key];
  399. }
  400. }