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

kr.jadekim.jext.gson.annotation.Exclude.kt Maven / Gradle / Ivy

package kr.jadekim.jext.gson.annotation

import com.google.gson.ExclusionStrategy
import com.google.gson.FieldAttributes

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FIELD)
annotation class Exclude(
    val serialize: Boolean = true,
    val deserialize: Boolean = true
)

class ExcludeFieldSerializeStrategy : ExclusionStrategy {

    override fun shouldSkipField(f: FieldAttributes?): Boolean =
        f?.getAnnotation(Exclude::class.java)?.serialize == true

    override fun shouldSkipClass(clazz: Class<*>?): Boolean = false
}

class ExcludeFieldDeserializeStrategy : ExclusionStrategy {

    override fun shouldSkipField(f: FieldAttributes?): Boolean =
        f?.getAnnotation(Exclude::class.java)?.deserialize == true

    override fun shouldSkipClass(clazz: Class<*>?): Boolean = false
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy