@@ -41,7 +41,7 @@ class GenericListClassGeneratorByJSONArray(private val jsonKey: String, jsonArra
4141 return GenericListClass (generic = dataClassFromJsonObj)
4242 }
4343 jsonArray.allItemAreArrayElement() -> {
44- val fatJsonArray = getFatJsonArray(jsonArray)
44+ val fatJsonArray = getFatJsonArray(jsonArray.map { it.asJsonArray } )
4545 val genericListClassFromFatJsonArray = GenericListClassGeneratorByJSONArray (jsonKey, fatJsonArray.toString()).generate()
4646 LogUtil .i(" $tag jsonArray allItemAreArrayElement, return GenericListClass with generic type ${genericListClassFromFatJsonArray.name} " )
4747 return GenericListClass (generic = genericListClassFromFatJsonArray)
@@ -57,13 +57,10 @@ class GenericListClassGeneratorByJSONArray(private val jsonKey: String, jsonArra
5757 return adjustPropertyNameForGettingArrayChildType(jsonKey)
5858 }
5959
60- private fun getFatJsonArray (jsonArray : JsonArray ): JsonArray {
61- if (jsonArray.size() == 0 || ! jsonArray.allItemAreArrayElement()) {
62- throw IllegalStateException (" input arg jsonArray must not be empty and all element should be json array! " )
63- }
60+ private fun getFatJsonArray (jsonArrayList : List <JsonArray >): JsonArray {
6461 val fatJsonArray = JsonArray ()
65- jsonArray .forEach {
66- fatJsonArray.addAll(it.asJsonArray )
62+ jsonArrayList .forEach {
63+ fatJsonArray.addAll(it)
6764 }
6865 return fatJsonArray
6966 }
@@ -87,11 +84,19 @@ class GenericListClassGeneratorByJSONArray(private val jsonKey: String, jsonArra
8784 // and will not be generated in final code
8885 fatJsonObject.add(key + BACKSTAGE_NULLABLE_POSTFIX , value)
8986 } else if (fatJsonObject.has(key)) {
90- if (fatJsonObject[key].isJsonObject && value.isJsonObject) {
87+ if (fatJsonObject[key].isJsonObject && value.isJsonObject) {// try not miss any fields of the key's related json object
9188 val newValue = getFatJsonObject(JsonArray ().apply { add(fatJsonObject[key]);add(value) })
9289 fatJsonObject.add(key, newValue)
90+ } else if (fatJsonObject[key].isJsonArray && value.isJsonArray) {// //try not miss any elements of the key's related json array
91+ val newValue = getFatJsonArray(listOf (fatJsonObject[key].asJsonArray, value.asJsonArray))
92+ fatJsonObject.add(key, newValue)
93+ } else if (fatJsonObject[key].isJsonPrimitive && value.isJsonPrimitive && theSamePrimitiveType(fatJsonObject[key].asJsonPrimitive, value.asJsonPrimitive)) {
94+ // if the value and exist value are the same primitive type then ignore it
95+ } else if (value.isJsonNull) {
96+ // if the value is null, we ignore this value
9397 } else {
94- fatJsonObject.add(key, value)
98+ // others the two values of the key are not the same type, then give it a null value indicate that it's should be an Any Type in Kotlin
99+ fatJsonObject.add(key, JsonNull .INSTANCE )
95100 }
96101 } else {
97102 fatJsonObject.add(key, value)
0 commit comments