summaryrefslogtreecommitdiff
path: root/runtime/commonMain/src/kotlinx/serialization/json/Deprecated.kt
blob: b1e6eed029b94b4d7c0b1f74b0577a108fff6a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

@file:UseExperimental(UnstableDefault::class)

package kotlinx.serialization.json

import kotlinx.serialization.*
import kotlinx.serialization.modules.*

@Deprecated(deprecationText, ReplaceWith("Json"), DeprecationLevel.WARNING)
typealias JSON = Json

@Deprecated(level = DeprecationLevel.WARNING, message = "Use Json methods instead")
class JsonTreeMapper(val encodeDefaults: Boolean = true) : AbstractSerialFormat(EmptyModule) {

    @ImplicitReflectionSerializer
    @Deprecated(level = DeprecationLevel.WARNING, message = "Use Json.fromJson instead", replaceWith = ReplaceWith("Json.plain.fromJson(tree)"))
    inline fun <reified T : Any> readTree(tree: JsonElement): T = Json.plain.fromJson(tree)

    @Deprecated(level = DeprecationLevel.WARNING, message = "Use Json.fromJson instead", replaceWith = ReplaceWith("Json.plain.fromJson(obj, deserializer)"))
    fun <T> readTree(obj: JsonElement, deserializer: DeserializationStrategy<T>): T =
        Json.plain.fromJson(deserializer, obj)

    @Deprecated(level = DeprecationLevel.WARNING, message = "Use Json.toJson instead", replaceWith = ReplaceWith("Json.plain.toJson(obj, serializer)"))
    fun <T> writeTree(obj: T, serializer: SerializationStrategy<T>): JsonElement = Json.plain.toJson(serializer, obj)
}

@Deprecated(level = DeprecationLevel.WARNING, message = "Use Json methods instead")
class JsonTreeParser(private val input: String) {

    companion object {
        @Deprecated(level = DeprecationLevel.WARNING, message = "Use Json.parse instead", replaceWith = ReplaceWith("Json.plain.parseJson(input)"))
        fun parse(input: String): JsonObject = Json.plain.parseJson(input) as JsonObject
    }

    fun readFully(): JsonElement {
        @Suppress("DEPRECATION")
        return Json.plain.parseJson(input)
    }
}