Add @Json.ignore (#1417)

* Default Json.name to an unset value

* Promote shared transient tests to DualKotlinTest

* Add new ignore property to Json

* Support it in ClassJsonAdapter

* Mention no enum/record support

* Support in KotlinJsonAdapter

* Rework code gen API to know of "ignored"

* Support in apt code gen

* Support in KSP

* Update old non-working transient example test

* Synthetic holders

* Use field on both
This commit is contained in:
Zac Sweers
2021-11-08 11:16:57 -05:00
committed by GitHub
parent 48e6dd3f03
commit 954ca46b9e
19 changed files with 317 additions and 108 deletions

View File

@@ -17,3 +17,7 @@
plugins {
kotlin("jvm")
}
dependencies {
implementation(project(":moshi"))
}

View File

@@ -15,10 +15,14 @@
*/
package com.squareup.moshi.kotlin.codegen.test.extra
import com.squareup.moshi.Json
public abstract class AbstractClassInModuleA {
// Transients to ensure processor sees them across module boundaries since @Transient is
// SOURCE-only
// TODO uncomment these when https://github.com/google/ksp/issues/710 is fixed
// @Transient private lateinit var lateinitTransient: String
// @Transient private var regularTransient: String = "regularTransient"
// Ignored to ensure processor sees them across module boundaries.
// @Transient doesn't work for this case because it's source-only and jvm modifiers aren't currently visible in KSP.
// Note that we target the field because otherwise it is stored on the synthetic holder method for
// annotations, which isn't visible from kapt
@field:Json(ignore = true) private lateinit var lateinitIgnored: String
@field:Json(ignore = true) private var regularIgnored: String = "regularIgnored"
}