Skip to content

Commit d17db9f

Browse files
committed
Stabilize JsonUnquotedLiteral
This is a widely popular solution to deal with BigDecimal and other numerals. Fixes #2900
1 parent e3d265d commit d17db9f

File tree

5 files changed

+3
-10
lines changed

5 files changed

+3
-10
lines changed

docs/json.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ In this chapter, we'll walk through features of [JSON](https://www.json.org/json
3030
* [Types of Json elements](#types-of-json-elements)
3131
* [Json element builders](#json-element-builders)
3232
* [Decoding Json elements](#decoding-json-elements)
33-
* [Encoding literal Json content (experimental)](#encoding-literal-json-content-experimental)
33+
* [Encoding literal Json content](#encoding-literal-json-content)
3434
* [Serializing large decimal numbers](#serializing-large-decimal-numbers)
3535
* [Using `JsonUnquotedLiteral` to create a literal unquoted value of `null` is forbidden](#using-jsonunquotedliteral-to-create-a-literal-unquoted-value-of-null-is-forbidden)
3636
* [Json transformations](#json-transformations)
@@ -913,9 +913,7 @@ Project(name=kotlinx.serialization, language=Kotlin)
913913

914914
<!--- TEST -->
915915

916-
### Encoding literal Json content (experimental)
917-
918-
> This functionality is experimental and requires opting-in to [the experimental Kotlinx Serialization API](compatibility.md#experimental-api).
916+
### Encoding literal Json content
919917

920918
In some cases it might be necessary to encode an arbitrary unquoted value.
921919
This can be achieved with [JsonUnquotedLiteral].
@@ -974,7 +972,6 @@ fun main() {
974972
val pi = BigDecimal("3.141592653589793238462643383279")
975973

976974
// use JsonUnquotedLiteral to encode raw JSON content
977-
@OptIn(ExperimentalSerializationApi::class)
978975
val piJsonLiteral = JsonUnquotedLiteral(pi.toString())
979976

980977
val piJsonDouble = JsonPrimitive(pi.toDouble())
@@ -1046,7 +1043,6 @@ To avoid creating an inconsistent state, encoding a String equal to `"null"` is
10461043
Use [JsonNull] or [JsonPrimitive] instead.
10471044

10481045
```kotlin
1049-
@OptIn(ExperimentalSerializationApi::class)
10501046
fun main() {
10511047
// caution: creating null with JsonUnquotedLiteral will cause an exception!
10521048
JsonUnquotedLiteral("null")

docs/serialization-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Once the project is set up, we can start serializing some classes.
131131
* <a name='types-of-json-elements'></a>[Types of Json elements](json.md#types-of-json-elements)
132132
* <a name='json-element-builders'></a>[Json element builders](json.md#json-element-builders)
133133
* <a name='decoding-json-elements'></a>[Decoding Json elements](json.md#decoding-json-elements)
134-
* <a name='encoding-literal-json-content-experimental'></a>[Encoding literal Json content (experimental)](json.md#encoding-literal-json-content-experimental)
134+
* <a name='encoding-literal-json-content'></a>[Encoding literal Json content](json.md#encoding-literal-json-content)
135135
* <a name='serializing-large-decimal-numbers'></a>[Serializing large decimal numbers](json.md#serializing-large-decimal-numbers)
136136
* <a name='using-jsonunquotedliteral-to-create-a-literal-unquoted-value-of-null-is-forbidden'></a>[Using `JsonUnquotedLiteral` to create a literal unquoted value of `null` is forbidden](json.md#using-jsonunquotedliteral-to-create-a-literal-unquoted-value-of-null-is-forbidden)
137137
* <a name='json-transformations'></a>[Json transformations](json.md#json-transformations)

formats/json/commonMain/src/kotlinx/serialization/json/JsonElement.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ public fun JsonPrimitive(value: Nothing?): JsonNull = JsonNull
123123
* @see JsonPrimitive is the preferred method for encoding JSON primitives.
124124
* @throws JsonEncodingException if `value == "null"`
125125
*/
126-
@ExperimentalSerializationApi
127126
@Suppress("FunctionName")
128127
public fun JsonUnquotedLiteral(value: String?): JsonPrimitive {
129128
return when (value) {

guide/example/example-json-23.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ fun main() {
1212
val pi = BigDecimal("3.141592653589793238462643383279")
1313

1414
// use JsonUnquotedLiteral to encode raw JSON content
15-
@OptIn(ExperimentalSerializationApi::class)
1615
val piJsonLiteral = JsonUnquotedLiteral(pi.toString())
1716

1817
val piJsonDouble = JsonPrimitive(pi.toDouble())

guide/example/example-json-25.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package example.exampleJson25
44
import kotlinx.serialization.*
55
import kotlinx.serialization.json.*
66

7-
@OptIn(ExperimentalSerializationApi::class)
87
fun main() {
98
// caution: creating null with JsonUnquotedLiteral will cause an exception!
109
JsonUnquotedLiteral("null")

0 commit comments

Comments
 (0)