Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 869a264

Browse files
committed
fix json serialization caring about order of elements in json
1 parent d4abe86 commit 869a264

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repositories {
2222
}
2323

2424
dependencies {
25-
implementation("io.github.dockyardmc:scroll:1.9")
25+
implementation("io.github.dockyardmc:scroll:2.3")
2626
}
2727
```
2828
<img src="https://github.com/LukynkaCZE/PrettyLog/assets/48604271/3293feca-7395-4100-8b61-257ba40dbe3c" width="18px"></img>
@@ -36,7 +36,7 @@ repositories {
3636
}
3737
3838
dependencies {
39-
implementation 'io.github.dockyardmc:scroll:1.9'
39+
implementation 'io.github.dockyardmc:scroll:2.3'
4040
}
4141
```
4242
---
@@ -110,16 +110,16 @@ The following tags are valid:
110110
- `<underline>`
111111
- `<strikethrough>`
112112
- Events
113-
- `<hover|'text''>` for hover-able text. Formatting applies to inner text as well
114-
- `<click|action|'text'>` for clickable text. Actions are following
113+
- `<hover:'text''>` for hover-able text. Formatting applies to inner text as well
114+
- `<click:action:'text'>` for clickable text. Actions are following
115115
- `open_url` - following text needs to start with "https://"
116116
- `run_command` - following text needs to start with "/"
117117
- `suggest_command` - following text needs to start with "/"
118118
- `copy_to_clipboard`
119119
- Other
120-
- `<font|'file_name'>` to change font
120+
- `<font:'file_name'>` to change font
121121
- `<rainbow>` to make the text after rainbow. (Resets when another color is applied or when <reset> is reached)
122-
- `<transition|#hex1|#hex2|step>` - Color Interpolation, step is float between 0 and 1
122+
- `<transition:#hex1:#hex2:step>` - Color Interpolation, step is float between 0 and 1
123123
- `<reset>` to reset formatting
124124

125125
In some cases (format and reset) you can use shortened versions

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group = "io.github.dockyardmc"
14-
version = "2.2"
14+
version = "2.3"
1515

1616
repositories {
1717
mavenCentral()

src/main/kotlin/io/github/dockyardmc/scroll/serializers/JsonToComponentSerializer.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import kotlinx.serialization.json.decodeFromJsonElement
77
object JsonToComponentSerializer {
88

99
fun serialize(json: String): Component {
10-
return Json.decodeFromJsonElement(Json.parseToJsonElement(json))
10+
val serializer = Json {
11+
ignoreUnknownKeys = true
12+
isLenient = true
13+
}
14+
15+
return Json.decodeFromJsonElement(serializer.parseToJsonElement(json))
1116
}
1217
}

src/test/kotlin/JsonSerializationTests.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
import io.github.dockyardmc.scroll.Component
12
import io.github.dockyardmc.scroll.serializers.JsonToComponentSerializer
23
import io.github.dockyardmc.scroll.extensions.toComponent
34
import kotlin.test.Test
45
import kotlin.test.assertEquals
56

67
class JsonSerializationTests {
78

9+
@Test
10+
fun testWrongOrder() {
11+
val input = "{\"color\":\"#FFAA00\",\"text\":\"Analysis is now complete.\"}"
12+
val component = JsonToComponentSerializer.serialize(input)
13+
val expected = "<gold>Analysis is now complete."
14+
15+
assertEquals(expected.toComponent().toJson(), Component.compound(mutableListOf(component)).toJson())
16+
}
17+
818
@Test
919
fun testComponentToJson() {
1020
val input = "<yellow>Osmanthus wine tastes <i>the same as <orange><bold>I remember<gray><i>... <yellow>But where are those who share <aqua><bold><u>the memory"

0 commit comments

Comments
 (0)