# 1. Prepare
If your project uses `kotlin`, you can use the` Fastjson-Kotlin` module, and use the characteristics of `kotlin`.
### 1.1 Download
`Maven`:
```xml
com.alibaba.fastjson2
fastjson2-kotlin
2.0.37
```
```xml
org.jetbrains.kotlin
kotlin-stdlib
${kotlin-version}
org.jetbrains.kotlin
kotlin-reflect
${kotlin-version}
```
* `Kotlin Gradle`:
```kotlin
dependencies {
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.37")
}
```
```kotlin
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version")
}
```
### 1.2 Import functions
Whenever the function in the `Fastjson-Kotlin`, you need to complete the import functions work, **otherwise it will be prompted that the corresponding function will not be found**.
E.g:
```kotlin
import com.alibaba.fastjson2.to
import com.alibaba.fastjson2.into
```
If you use a lot of functions, you can use batch import.
```kotlin
import com.alibaba.fastjson2.*
```
# 2. Usage
We have unified function names `to` and` into`.
- Use `to` to use `::class.java`, suitable for categories without generic Class.
- Use `into` to use the `TypeReference`, which is suitable for genetic Class.
First define a User class
```kotlin
class User(
var id: Int,
var name: String
)
```
### 2.1 Parse `JSON` into `JSONObject`
```kotlin
val text = "..." // String
val data = text.parseObject()
val bytes = ... // ByteArray
val data = bytes.parseObject() // JSONObject
```
### 2.2 Parse `JSON` into `JSONArray`
`Kotlin`:
```kotlin
val text = "..." // String
val data = text.parseArray() // JSONArray
```
### 2.2 Create the `Typereference` of specified Class
```kotlin
val refer = reference()
```
### 2.3 Parse `JSON` into an Object
No generic:
```kotlin
val text = "..." // String
val data = text.to() // User
```
Including generic:
```kotlin
val text = "..." // String
val data = text.into>() // List
val data = text.into