From 494e9239002dc6425cf0e2df9463d933098b431f Mon Sep 17 00:00:00 2001 From: Sergio Pro Date: Sat, 22 Oct 2022 20:59:57 +0200 Subject: [PATCH] Start using json files as dictionaries --- .../io.github.serpro69/cli-bot/resource-config.json | 2 +- core/build.gradle.kts | 1 - .../kotlin/io/github/serpro69/kfaker/FakerService.kt | 10 +++++----- .../main/kotlin/io/github/serpro69/kfaker/Mapper.kt | 11 +++++------ 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cli-bot/src/main/resources/META-INF/native-image/io.github.serpro69/cli-bot/resource-config.json b/cli-bot/src/main/resources/META-INF/native-image/io.github.serpro69/cli-bot/resource-config.json index 116eacce0..e25ddfca8 100644 --- a/cli-bot/src/main/resources/META-INF/native-image/io.github.serpro69/cli-bot/resource-config.json +++ b/cli-bot/src/main/resources/META-INF/native-image/io.github.serpro69/cli-bot/resource-config.json @@ -11,7 +11,7 @@ {"pattern":"\\Qkotlin/ranges/ranges.kotlin_builtins\\E"}, {"pattern":"\\Qkotlin/reflect/reflect.kotlin_builtins\\E"}, {"pattern":"\\Qsun/text/resources/LineBreakIteratorData\\E"}, - {"pattern": ".*/*.yml$"} + {"pattern": ".*/*.json$"} ] } } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 10401ffd5..bb1f7766b 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -15,7 +15,6 @@ plugins { dependencies { implementation("com.fasterxml.jackson.core:jackson-databind:2.13.4.2") - implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.4") implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.4") implementation("org.yaml:snakeyaml:1.33") implementation("com.ibm.icu:icu4j:71.1") diff --git a/core/src/main/kotlin/io/github/serpro69/kfaker/FakerService.kt b/core/src/main/kotlin/io/github/serpro69/kfaker/FakerService.kt index e9fde9df4..a90ef37fe 100644 --- a/core/src/main/kotlin/io/github/serpro69/kfaker/FakerService.kt +++ b/core/src/main/kotlin/io/github/serpro69/kfaker/FakerService.kt @@ -64,8 +64,8 @@ internal class FakerService { secondaryCategory: Category? ): InputStream { return secondaryCategory?.let { - requireNotNull(javaClass.classLoader.getResourceAsStream("locales/$locale/${it.lowercase()}.yml")) - } ?: requireNotNull(javaClass.classLoader.getResourceAsStream("locales/$locale/${category.lowercase()}.yml")) + requireNotNull(javaClass.classLoader.getResourceAsStream("locales/$locale/${it.lowercase()}.json")) + } ?: requireNotNull(javaClass.classLoader.getResourceAsStream("locales/$locale/${category.lowercase()}.json")) } private fun getCategoryFileStreamOrNull( @@ -74,12 +74,12 @@ internal class FakerService { secondaryCategory: Category? ): InputStream? { return secondaryCategory?.let { - javaClass.classLoader.getResourceAsStream("locales/$locale/${it.lowercase()}.yml") - } ?: javaClass.classLoader.getResourceAsStream("locales/$locale/${category.lowercase()}.yml") + javaClass.classLoader.getResourceAsStream("locales/$locale/${it.lowercase()}.json") + } ?: javaClass.classLoader.getResourceAsStream("locales/$locale/${category.lowercase()}.json") } private fun getLocaleFileStream(locale: String): InputStream? { - return javaClass.classLoader.getResourceAsStream("locales/$locale.yml") + return javaClass.classLoader.getResourceAsStream("locales/$locale.json") } /** diff --git a/core/src/main/kotlin/io/github/serpro69/kfaker/Mapper.kt b/core/src/main/kotlin/io/github/serpro69/kfaker/Mapper.kt index 0a9a24ae2..9175cc83b 100644 --- a/core/src/main/kotlin/io/github/serpro69/kfaker/Mapper.kt +++ b/core/src/main/kotlin/io/github/serpro69/kfaker/Mapper.kt @@ -1,15 +1,14 @@ package io.github.serpro69.kfaker -import com.fasterxml.jackson.databind.* -import com.fasterxml.jackson.dataformat.yaml.* -import com.fasterxml.jackson.module.kotlin.* -import java.io.* +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.KotlinModule +import java.io.InputStream internal object Mapper { - private val mapper = ObjectMapper(YAMLFactory()) + private val mapper = ObjectMapper() init { - mapper.registerModule(KotlinModule()) + mapper.registerModule(KotlinModule.Builder().build()) } fun readValue(inputStream: InputStream, type: Class): T = mapper.readerFor(type).readValue(inputStream)