All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gsonpath.adapter.standard.model.GsonModelIndexAssigner.kt Maven / Gradle / Ivy

Go to download

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)
                        }
                    }
                }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy