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

com.alibaba.fastjson2.JSONObject.kt Maven / Gradle / Ivy

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
)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy