diff --git a/src/main/kotlin/com/github/zhangruiyu/flutterjsonbeanfactory/action/dart_to_helper/FlutterBeanFactoryAction.kt b/src/main/kotlin/com/github/zhangruiyu/flutterjsonbeanfactory/action/dart_to_helper/FlutterBeanFactoryAction.kt index a0a8f0e..9d0be63 100644 --- a/src/main/kotlin/com/github/zhangruiyu/flutterjsonbeanfactory/action/dart_to_helper/FlutterBeanFactoryAction.kt +++ b/src/main/kotlin/com/github/zhangruiyu/flutterjsonbeanfactory/action/dart_to_helper/FlutterBeanFactoryAction.kt @@ -76,9 +76,13 @@ class FlutterBeanFactoryAction : AnAction() { content.append("typedef JsonConvertFunction = T Function(Map json);") content.append("\n") content.append("typedef EnumConvertFunction = T Function(String value);") + content.append("\n") + content.append("typedef ConvertExceptionHandler = void Function(Object error, StackTrace stackTrace);") content.append("\n\n") content.append("class JsonConvert {") content.append("\n") + content.append("\tstatic ConvertExceptionHandler? onError;") + content.append("\n") content.append("\tstatic Map get convertFuncMap => {") content.append("\n") allClass.forEach { itemClass -> @@ -100,6 +104,9 @@ class FlutterBeanFactoryAction : AnAction() { " return _asT(value, enumConvert: enumConvert);\n" + " } catch (e, stackTrace) {\n" + " debugPrint('asT<${"\$T"}> ${"\$e"} ${"\$stackTrace"}');\n" + + " if (onError != null) {" + + " onError!(e, stackTrace);" + + " }"+ " return null;\n" + " }\n" + " }" @@ -114,6 +121,9 @@ class FlutterBeanFactoryAction : AnAction() { " return value.map((dynamic e) => _asT(e,enumConvert: enumConvert)).toList();\n" + " } catch (e, stackTrace) {\n" + " debugPrint('asT<${"\$T"}> ${"\$e"} ${"\$stackTrace"}');\n" + + " if (onError != null) {" + + " onError!(e, stackTrace);" + + " }"+ " return [];\n" + " }\n" + " }" @@ -128,6 +138,9 @@ class FlutterBeanFactoryAction : AnAction() { " return (value as List).map((dynamic e) => _asT(e,enumConvert: enumConvert)!).toList();\n" + " } catch (e, stackTrace) {\n" + " debugPrint('asT<${"\$T"}> ${"\$e"} ${"\$stackTrace"}');\n" + + " if (onError != null) {" + + " onError!(e, stackTrace);" + + " }"+ " return [];\n" + " }\n" + " }"