Skip to content

Commit

Permalink
Fix guide paths
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad committed Mar 21, 2022
1 parent 1e43dd3 commit 85dce74
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
8 changes: 4 additions & 4 deletions docs/basic-serialization.md
Expand Up @@ -297,7 +297,7 @@ fun main() {
It produces the exception:

```text
Exception in thread "main" kotlinx.serialization.MissingFieldException: Field 'language' is required for type with serial name 'example.exampleClasses04.Project', but it was missing
Exception in thread "main" kotlinx.serialization.MissingFieldException: Field 'language' is required for type with serial name 'example.exampleClasses04.Project', but it was missing at path: $
```

<!--- TEST LINES_START -->
Expand Down Expand Up @@ -383,7 +383,7 @@ fun main() {
We get the following exception.

```text
Exception in thread "main" kotlinx.serialization.MissingFieldException: Field 'language' is required for type with serial name 'example.exampleClasses07.Project', but it was missing
Exception in thread "main" kotlinx.serialization.MissingFieldException: Field 'language' is required for type with serial name 'example.exampleClasses07.Project', but it was missing at path: $
```

<!--- TEST LINES_START -->
Expand Down Expand Up @@ -411,7 +411,7 @@ Attempts to explicitly specify its value in the serial format, even if the speci
value is equal to the default one, produces the following exception.

```text
Exception in thread "main" kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 42: Encountered an unknown key 'language'.
Exception in thread "main" kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 42: Encountered an unknown key 'language' at path: $.name
Use 'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown keys.
```

Expand Down Expand Up @@ -493,7 +493,7 @@ Even though the `language` property has a default value, it is still an error to
the `null` value to it.

```text
Exception in thread "main" kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 52: Expected string literal but 'null' literal was found.
Exception in thread "main" kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 52: Expected string literal but 'null' literal was found at path: $.language
Use 'coerceInputValues = true' in 'Json {}` builder to coerce nulls to default values.
```

Expand Down
Expand Up @@ -90,7 +90,6 @@ internal class JsonPath {

@OptIn(ExperimentalSerializationApi::class)
fun getPath(): String {
if (currentDepth == -1) return ""
return buildString {
append("$")
repeat(currentDepth + 1) {
Expand Down
Expand Up @@ -32,6 +32,13 @@ class JsonPathTest : JsonTestBase() {
expectPath("$.i.d[1]") { Json.decodeFromString<Outer>("""{"a":42, "i":{"d":{1:{}}""") }
}

@Test
fun testUnknownKeyIsProperlyReported() {
expectPath("$.i") { Json.decodeFromString<Outer>("""{"a":42, "i":{"foo":42}""") }
expectPath("$") { Json.decodeFromString<Outer>("""{"x":{}, "a": 42}""") }
// Json.decodeFromString<Outer>("""{"a":42, "x":{}}""")
}

@Test
fun testMalformedRootObject() {
expectPath("$") { Json.decodeFromString<Outer>("""{{""") }
Expand All @@ -58,6 +65,7 @@ class JsonPathTest : JsonTestBase() {
expectPath("$.i.d\n") { Json.decodeFromString<Outer>("""{"a":42, "i":{ "d": {"foo": {}}""") }
expectPath("$.i.d\n") { Json.decodeFromString<Outer>("""{"a":42, "i":{ "d": {42: {"s":"s"}, 42.0:{}}""") }
expectPath("$\n") { Json.decodeFromString<Map<Int, String>>("""{"foo":"bar"}""") }
expectPath("$\n") { Json.decodeFromString<Map<Int, String>>("""{42:"bar", "foo":"bar"}""") }
}

@Test
Expand Down
8 changes: 4 additions & 4 deletions guide/test/BasicSerializationTest.kt
Expand Up @@ -51,7 +51,7 @@ class BasicSerializationTest {
@Test
fun testExampleClasses04() {
captureOutput("ExampleClasses04") { example.exampleClasses04.main() }.verifyOutputLinesStart(
"Exception in thread \"main\" kotlinx.serialization.MissingFieldException: Field 'language' is required for type with serial name 'example.exampleClasses04.Project', but it was missing"
"Exception in thread \"main\" kotlinx.serialization.MissingFieldException: Field 'language' is required for type with serial name 'example.exampleClasses04.Project', but it was missing at path: $"
)
}

Expand All @@ -72,14 +72,14 @@ class BasicSerializationTest {
@Test
fun testExampleClasses07() {
captureOutput("ExampleClasses07") { example.exampleClasses07.main() }.verifyOutputLinesStart(
"Exception in thread \"main\" kotlinx.serialization.MissingFieldException: Field 'language' is required for type with serial name 'example.exampleClasses07.Project', but it was missing"
"Exception in thread \"main\" kotlinx.serialization.MissingFieldException: Field 'language' is required for type with serial name 'example.exampleClasses07.Project', but it was missing at path: $"
)
}

@Test
fun testExampleClasses08() {
captureOutput("ExampleClasses08") { example.exampleClasses08.main() }.verifyOutputLinesStart(
"Exception in thread \"main\" kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 42: Encountered an unknown key 'language'.",
"Exception in thread \"main\" kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 42: Encountered an unknown key 'language' at path: $.name",
"Use 'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown keys."
)
}
Expand All @@ -101,7 +101,7 @@ class BasicSerializationTest {
@Test
fun testExampleClasses11() {
captureOutput("ExampleClasses11") { example.exampleClasses11.main() }.verifyOutputLinesStart(
"Exception in thread \"main\" kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 52: Expected string literal but 'null' literal was found.",
"Exception in thread \"main\" kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 52: Expected string literal but 'null' literal was found at path: $.language",
"Use 'coerceInputValues = true' in 'Json {}` builder to coerce nulls to default values."
)
}
Expand Down

0 comments on commit 85dce74

Please sign in to comment.