mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 07:59:21 +08:00
Add KSP docs to README (#1455)
* Add KSP docs to README * Open KSP * spotless
This commit is contained in:
31
README.md
31
README.md
@@ -1069,9 +1069,9 @@ Note that the reflection adapter transitively depends on the `kotlin-reflect` li
|
|||||||
|
|
||||||
#### Codegen
|
#### Codegen
|
||||||
|
|
||||||
Moshi’s Kotlin codegen support is an annotation processor. It generates a small and fast adapter for
|
Moshi’s Kotlin codegen support can be used as an annotation processor (via [kapt][kapt]) or Kotlin SymbolProcessor ([KSP][ksp]).
|
||||||
each of your Kotlin classes at compile time. Enable it by annotating each class that you want to
|
It generates a small and fast adapter for each of your Kotlin classes at compile-time. Enable it by annotating
|
||||||
encode as JSON:
|
each class that you want to encode as JSON:
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
@@ -1084,9 +1084,27 @@ data class BlackjackHand(
|
|||||||
The codegen adapter requires that your Kotlin types and their properties be either `internal` or
|
The codegen adapter requires that your Kotlin types and their properties be either `internal` or
|
||||||
`public` (this is Kotlin’s default visibility).
|
`public` (this is Kotlin’s default visibility).
|
||||||
|
|
||||||
Kotlin codegen has no additional runtime dependency. You’ll need to [enable kapt][kapt] and then
|
Kotlin codegen has no additional runtime dependency. You’ll need to enable kapt or KSP and then
|
||||||
add the following to your build to enable the annotation processor:
|
add the following to your build to enable the annotation processor:
|
||||||
|
|
||||||
|
<details open>
|
||||||
|
<summary>KSP</summary>
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
plugins {
|
||||||
|
id("com.google.devtools.ksp").version("1.6.0-1.0.1")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
ksp("com.squareup.moshi:moshi-kotlin-codegen:1.13.0")
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Kapt</summary>
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.moshi</groupId>
|
<groupId>com.squareup.moshi</groupId>
|
||||||
@@ -1099,9 +1117,7 @@ add the following to your build to enable the annotation processor:
|
|||||||
```kotlin
|
```kotlin
|
||||||
kapt("com.squareup.moshi:moshi-kotlin-codegen:1.13.0")
|
kapt("com.squareup.moshi:moshi-kotlin-codegen:1.13.0")
|
||||||
```
|
```
|
||||||
|
</details>
|
||||||
You must also have the `kotlin-stdlib` dependency on the classpath during compilation in order for
|
|
||||||
the compiled code to have the required metadata annotations that Moshi's processor looks for.
|
|
||||||
|
|
||||||
#### Limitations
|
#### Limitations
|
||||||
|
|
||||||
@@ -1168,3 +1184,4 @@ License
|
|||||||
[gson]: https://github.com/google/gson/
|
[gson]: https://github.com/google/gson/
|
||||||
[javadoc]: https://square.github.io/moshi/1.x/moshi/
|
[javadoc]: https://square.github.io/moshi/1.x/moshi/
|
||||||
[kapt]: https://kotlinlang.org/docs/reference/kapt.html
|
[kapt]: https://kotlinlang.org/docs/reference/kapt.html
|
||||||
|
[ksp]: https://github.com/google/ksp
|
||||||
|
Reference in New Issue
Block a user