gsonpath.adapter.standard.model.GsonModelIndexAssigner.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gsonpath-compiler Show documentation
Show all versions of gsonpath-compiler Show documentation
An annotation processor which generates Type Adapters for the Google Gson library
The newest version!
package gsonpath.adapter.standard.model
object GsonModelIndexAssigner {
fun assignObjectIndexes(gsonObject: GsonObject): List {
val results = gsonObject.entries()
.flatMap { (_, gsonType) ->
when (gsonType) {
is GsonField -> emptyList()
is GsonObject -> assignObjectIndexes(gsonType)
is GsonArray -> {
gsonType.entries()
.flatMap { (_, arrayGsonType) ->
when (arrayGsonType) {
is GsonField -> emptyList()
is GsonObject -> assignObjectIndexes(arrayGsonType)
}
}
}
}
}
return listOf(gsonObject).plus(results)
}
fun assignArrayIndexes(gsonObject: GsonObject): List {
return gsonObject.entries()
.flatMap { (_, gsonType) ->
when (gsonType) {
is GsonField -> emptyList()
is GsonObject -> assignArrayIndexes(gsonType)
is GsonArray -> {
val results = gsonType.entries()
.flatMap { (_, arrayGsonType) ->
when (arrayGsonType) {
is GsonField -> emptyList()
is GsonObject -> assignArrayIndexes(arrayGsonType)
}
}
listOf(gsonType).plus(results)
}
}
}
}
}