Skip to content

Commit ed140e8

Browse files
list的datetime支持
1 parent 4e580f6 commit ed140e8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
kotlin_version=1.3.61
2-
pluginVersion=3.1.9
2+
pluginVersion=3.2.0
33
#每次修改这里去打包
44
ideaVersionPrefix=193
55
ideaVersion=

src/main/java/com/ruiyu/jsontodart/ClassGeneratorInfo.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class HelperClassGeneratorInfo {
6161
"if (json['$getJsonName'] != null) {\n\t\tdata.$name = json['$getJsonName']?.map((v) => v${buildToType(getListSubType(type))})?.toList()?.cast<${getListSubType(type)}>();\n\t}"
6262
}
6363
type == "DateTime" -> {
64-
if(filed.getValueByName<String>("format")?.isNotEmpty() == true){
64+
if (filed.getValueByName<String>("format")?.isNotEmpty() == true) {
6565
"if(json['$getJsonName'] != null){\n\t\tDateFormat format = new DateFormat(\"${filed.getValueByName<String>("format")}\");\n\t\tdata.$name = format.parse(json['$getJsonName'].toString());\n\t}"
66-
}else{
66+
} else {
6767
"if(json['$getJsonName'] != null){\n\t\tdata.$name = DateTime.tryParse(json['$getJsonName']);\n\t}"
6868
}
6969

@@ -78,7 +78,12 @@ class HelperClassGeneratorInfo {
7878
val listSubType = getListSubType(type)
7979
val value = when (listSubType) {
8080
"dynamic" -> "data.${name}.addAll(json['$getJsonName']);"
81-
"DateTime" -> "(json['$getJsonName'] as List).forEach((v) {\n\t\t\tdata.$name.add(DateTime.parse(v));\n\t\t});".trimIndent()
81+
"DateTime" ->
82+
if (filed.getValueByName<String>("format")?.isNotEmpty() == true) {
83+
"\n\t\tDateFormat format = new DateFormat(\"${filed.getValueByName<String>("format")}\");\n\t\t\t(json['$getJsonName'] as List).forEach((v) {\n\t\t\t\tif (v != null)\n\t\t\t\t\tdata.$name.add(format.parse(v.toString()));\n\t\t\t});".trimIndent()
84+
} else {
85+
"(json['$getJsonName'] as List).forEach((v) {\n\t\t\tdata.$name.add(DateTime.parse(v));\n\t\t});".trimIndent()
86+
}
8287
else -> "(json['$getJsonName'] as List).forEach((v) {\n\t\t\tdata.$name.add(new ${listSubType}().fromJson(v));\n\t\t});".trimIndent()
8388
}
8489
"if (json['$getJsonName'] != null) {\n\t\tdata.$name = new List<${listSubType}>();\n\t\t$value\n\t}"

0 commit comments

Comments
 (0)