44import org .jetbrains .annotations .NotNull ;
55
66import java .util .HashSet ;
7+ import java .util .Iterator ;
78import java .util .Map ;
89import java .util .Set ;
910
@@ -64,7 +65,7 @@ private void appendJsonObject(StringBuilder stringBuilder, JsonObject jsonObject
6465 String type = "String" ;
6566 if (jsonElementValue .isJsonArray ()) {
6667 type = getArrayType (property , (JsonArray ) jsonElementValue );
67- addProperty (stringBuilder , property , type , null );
68+ addProperty (stringBuilder , property , type , "" );
6869 } else if (jsonElementValue .isJsonPrimitive ()) {
6970 type = getPrimitiveType (jsonElementValue );
7071 addProperty (stringBuilder , property , type , jsonElementValue .getAsString ());
@@ -87,28 +88,35 @@ private String getJsonObjectType(String property, JsonObject jsonElementValue) {
8788
8889 @ NotNull
8990 private String getArrayType (String property , JsonArray jsonElementValue ) {
90- String type = "String" ;
91+ String type = "List< String> " ;
9192 JsonArray jsonArray = jsonElementValue ;
92- JsonElement next = jsonArray .iterator ().next ();
93- if (next .isJsonPrimitive ()) {
94- String subType = getPrimitiveType (next );
95- type = "List" + "<" + subType + ">" ;
96-
97- } else if (next .isJsonObject ()) {
98- property = modifyPropertyForArrayObjType (property );
99- String subType = getJsonObjectType (property , (JsonObject ) next );
100- type = "List" + "<" + subType + ">" ;
101- /**
102- * 处理子类
103- */
104- toBeAppend .add (new KotlinMaker (subType , next ).makeKotlinData ());
105- } else if (next .isJsonArray ()) {
106- property = modifyPropertyForArrayObjType (property );
107- String subType = getArrayType (property , (JsonArray ) next );
108- type = "List" + "<" + subType + ">" ;
109-
110- } else if (next .isJsonNull ()) {
111- type = "List" + "<" + "String" + ">" ;
93+
94+ Iterator <JsonElement > iterator = jsonArray .iterator ();
95+ if (iterator .hasNext ()) {
96+ JsonElement next = iterator .next ();
97+ if (next .isJsonPrimitive ()) {
98+ String subType = getPrimitiveType (next );
99+ type = "List" + "<" + subType + ">" ;
100+
101+ } else if (next .isJsonObject ()) {
102+ property = modifyPropertyForArrayObjType (property );
103+ String subType = getJsonObjectType (property , (JsonObject ) next );
104+ type = "List" + "<" + subType + ">" ;
105+ /**
106+ * 处理子类
107+ */
108+ toBeAppend .add (new KotlinMaker (subType , next ).makeKotlinData ());
109+ } else if (next .isJsonArray ()) {
110+ property = modifyPropertyForArrayObjType (property );
111+ String subType = getArrayType (property , (JsonArray ) next );
112+ type = "List" + "<" + subType + ">" ;
113+
114+ } else if (next .isJsonNull ()) {
115+ type = "List" + "<" + "String" + ">" ;
116+
117+ }
118+ } else {
119+ type = "List<Any>" ;
112120
113121 }
114122 return type ;
@@ -144,15 +152,14 @@ private String modifyPropertyForArrayObjType(String property) {
144152 }
145153
146154 private void addProperty (StringBuilder stringBuilder , String property , String type , String value ) {
147- String propertyKeyword = PropertyKeyword .INSTANCE .get ();
148- stringBuilder .append ("\t \t " + propertyKeyword + " " ).append (property ).append (": " ).append (type ).append ("," );
149- if (value != null ) {
150- stringBuilder .append ("// " ).append (value ).append ("\n " );
151- } else {
152- stringBuilder .append ("\n " );
155+ if (value == null ) {
156+ value = "null" ;
153157 }
158+ stringBuilder .append (new KProperty (property , type , value ).getPropertyStringBlock ());
159+ stringBuilder .append ("\n " );
154160 }
155161
162+
156163 @ NotNull
157164 private String getPrimitiveType (JsonElement next ) {
158165 String subType = "String" ;
0 commit comments