aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util/json
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-05-30 22:47:56 +0200
committernea <nea@nea.moe>2023-05-30 22:47:56 +0200
commit88cb9468b4432f68d1197f512f68c951fdbdf3dd (patch)
treefb9da150d4173cbe33d68b80c6d86240fe03c4e2 /src/main/kotlin/moe/nea/firmament/util/json
parent3139306088f8d3cad1b4906c3bbd1b412b9bda6f (diff)
downloadfirmament-88cb9468b4432f68d1197f512f68c951fdbdf3dd.tar.gz
firmament-88cb9468b4432f68d1197f512f68c951fdbdf3dd.tar.bz2
firmament-88cb9468b4432f68d1197f512f68c951fdbdf3dd.zip
Forge recipes and coin items
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util/json')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/json/DashlessUUIDSerializer.kt24
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/json/InstantAsLongSerializer.kt20
2 files changed, 44 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/json/DashlessUUIDSerializer.kt b/src/main/kotlin/moe/nea/firmament/util/json/DashlessUUIDSerializer.kt
new file mode 100644
index 0000000..c95b343
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/util/json/DashlessUUIDSerializer.kt
@@ -0,0 +1,24 @@
+package moe.nea.firmament.util.json
+
+import java.util.UUID
+import kotlinx.serialization.KSerializer
+import kotlinx.serialization.Serializer
+import kotlinx.serialization.descriptors.PrimitiveKind
+import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
+import kotlinx.serialization.descriptors.SerialDescriptor
+import kotlinx.serialization.encoding.Decoder
+import kotlinx.serialization.encoding.Encoder
+import moe.nea.firmament.util.parseDashlessUUID
+
+object DashlessUUIDSerializer : KSerializer<UUID> {
+ override val descriptor: SerialDescriptor =
+ PrimitiveSerialDescriptor("DashlessUUIDSerializer", PrimitiveKind.STRING)
+
+ override fun deserialize(decoder: Decoder): UUID {
+ return parseDashlessUUID(decoder.decodeString())
+ }
+
+ override fun serialize(encoder: Encoder, value: UUID) {
+ encoder.encodeString(value.toString().replace("-", ""))
+ }
+}
diff --git a/src/main/kotlin/moe/nea/firmament/util/json/InstantAsLongSerializer.kt b/src/main/kotlin/moe/nea/firmament/util/json/InstantAsLongSerializer.kt
new file mode 100644
index 0000000..988c7dd
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/util/json/InstantAsLongSerializer.kt
@@ -0,0 +1,20 @@
+package moe.nea.firmament.util.json
+
+import kotlinx.datetime.Instant
+import kotlinx.serialization.KSerializer
+import kotlinx.serialization.descriptors.PrimitiveKind
+import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
+import kotlinx.serialization.descriptors.SerialDescriptor
+import kotlinx.serialization.encoding.Decoder
+import kotlinx.serialization.encoding.Encoder
+
+object InstantAsLongSerializer : KSerializer<Instant> {
+ override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("InstantAsLongSerializer", PrimitiveKind.LONG)
+ override fun deserialize(decoder: Decoder): Instant {
+ return Instant.fromEpochMilliseconds(decoder.decodeLong())
+ }
+
+ override fun serialize(encoder: Encoder, value: Instant) {
+ encoder.encodeLong(value.toEpochMilliseconds())
+ }
+}