com.alibaba.fastjson2.JSONObject.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastjson2-kotlin Show documentation
Show all versions of fastjson2-kotlin Show documentation
kotlin integration for Fastjson2
The newest version!
@file:Suppress(
"HasPlatformType"
)
package com.alibaba.fastjson2
/**
* E.g.
* ```
* val data = "...".parseObject()
* val user = data.to()
* ```
*
* @return [T]?
* @since 2.0.3
*/
inline fun JSONObject.to(
vararg features: JSONReader.Feature
) = to(
T::class.java, *features
)
/**
* Implemented using [TypeReference]
*
* E.g.
* ```
* val data = "...".parseObject()
* val user = data.into()
* ```
*
* @return [T]?
* @since 2.0.4
*/
inline fun JSONObject.into(
vararg features: JSONReader.Feature
) = to(
reference().getType(), *features
)
/**
* E.g.
* ```
* // JSONObject
* val data = "...".parseObject()
* val user = data.to("key")
* ```
*
* @return [T]?
* @since 2.0.4
*/
inline fun JSONObject.to(
key: String,
vararg features: JSONReader.Feature
) = getObject(
key, T::class.java, *features
)
/**
* Implemented using [TypeReference]
*
* E.g.
* ```
* val data = "...".parseObject()
* val users = data.into>("key")
* ```
*
* @return [T]?
* @since 2.0.4
*/
inline fun JSONObject.into(
key: String,
vararg features: JSONReader.Feature
) = getObject(
key, reference().getType(), *features
)