From 2c362c718f3d6c2c4ec6e82ea1a6621d6b6f4fed Mon Sep 17 00:00:00 2001 From: "hh.jang" Date: Sat, 3 Aug 2024 10:03:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?faet:=20=EC=98=88=EC=A0=9C=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=EC=A0=9D=ED=8A=B8=20=EB=B0=8F=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=EC=A7=80=EC=A0=90=20=EC=A0=95=EC=A0=81=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=EB=90=98=EA=B2=8C=20=EC=B6=94=EA=B0=80=20(#1?= =?UTF-8?q?2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 ++++ HELP.md | 27 ----------------- examples/spring-boot-kotlin/build.gradle.kts | 8 +++-- .../example/SpringBootKotlinApplication.kt | 29 ++++++++++++++++++- .../factory/DefaultCsvCreatorFactory.kt | 7 +++++ 5 files changed, 47 insertions(+), 30 deletions(-) delete mode 100644 HELP.md diff --git a/.gitignore b/.gitignore index d9ed4f5..e50723a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +### 예제 샘프 ### +examples/ +examples/spring-boot-kotlin/.idea/ + + + ### intellij ### *.iml .idea/ diff --git a/HELP.md b/HELP.md deleted file mode 100644 index 623f426..0000000 --- a/HELP.md +++ /dev/null @@ -1,27 +0,0 @@ -# Read Me First -The following was discovered as part of building this project: - -* The JVM level was changed from '22' to '21' as the Kotlin version does not support Java 22 yet. - -# Getting Started - -### Reference Documentation -For further reference, please consider the following sections: - -* [Official Gradle documentation](https://docs.gradle.org) -* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.3.2/gradle-plugin) -* [Create an OCI image](https://docs.spring.io/spring-boot/3.3.2/gradle-plugin/packaging-oci-image.html) -* [Spring Web](https://docs.spring.io/spring-boot/docs/3.3.2/reference/htmlsingle/index.html#web) - -### Guides -The following guides illustrate how to use some features concretely: - -* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) -* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) -* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) - -### Additional Links -These additional references should also help you: - -* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) - diff --git a/examples/spring-boot-kotlin/build.gradle.kts b/examples/spring-boot-kotlin/build.gradle.kts index 33ad649..4dff5fd 100644 --- a/examples/spring-boot-kotlin/build.gradle.kts +++ b/examples/spring-boot-kotlin/build.gradle.kts @@ -13,12 +13,16 @@ java { languageVersion = JavaLanguageVersion.of(21) } } - repositories { - mavenCentral() + mavenCentral() + maven { url = uri("https://jitpack.io") } } dependencies { + // 오픈소스 프로젝트 추가 + // Add open-source project + implementation("com.github.hyunolike:json-csv-bridge:v0.0.3") + implementation("org.springframework.boot:spring-boot-starter-web") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.jetbrains.kotlin:kotlin-reflect") diff --git a/examples/spring-boot-kotlin/src/main/kotlin/com/example/SpringBootKotlinApplication.kt b/examples/spring-boot-kotlin/src/main/kotlin/com/example/SpringBootKotlinApplication.kt index 478cf7e..012cbb7 100644 --- a/examples/spring-boot-kotlin/src/main/kotlin/com/example/SpringBootKotlinApplication.kt +++ b/examples/spring-boot-kotlin/src/main/kotlin/com/example/SpringBootKotlinApplication.kt @@ -1,11 +1,38 @@ package com.example +import com.jsoncsvbridge.factory.DefaultCsvCreatorFactory +import org.springframework.boot.CommandLineRunner import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication +import org.springframework.stereotype.Component +import java.io.File @SpringBootApplication class SpringBootKotlinApplication fun main(args: Array) { - runApplication(*args) + runApplication(*args) } + +@Component +class CsvCreatorRunner() : CommandLineRunner { + override fun run(vararg args: String) { + val outputDir = File("csv_output").apply { mkdirs() } + + // JSON to CSV + val jsonCreator = DefaultCsvCreatorFactory().createCsvCreator("json"); + val jsonOutputPath = outputDir.resolve("output_json.csv").absolutePath + + // JSON to CSV + val jsonInput = """ + [ + {"name": "Alice", "age": 30, "city": "New York"}, + {"name": "Bob", "age": 25, "city": "Los Angeles"}, + {"name": "Charlie", "age": 35, "city": "Chicago"} + ] + """ + + jsonCreator.createCsv(jsonInput, jsonOutputPath) + println("JSON to CSV conversion completed. File saved at: $jsonOutputPath") + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/jsoncsvbridge/factory/DefaultCsvCreatorFactory.kt b/src/main/kotlin/com/jsoncsvbridge/factory/DefaultCsvCreatorFactory.kt index 0fb0bc2..fc82202 100644 --- a/src/main/kotlin/com/jsoncsvbridge/factory/DefaultCsvCreatorFactory.kt +++ b/src/main/kotlin/com/jsoncsvbridge/factory/DefaultCsvCreatorFactory.kt @@ -20,4 +20,11 @@ class DefaultCsvCreatorFactory : CsvCreatorFactory { else -> throw IllegalArgumentException("Unknown type") } } + + companion object { + @JvmStatic + fun createCsvCreator(type: String): CsvCreator { + return DefaultCsvCreatorFactory().createCsvCreator(type) + } + } } \ No newline at end of file From 84ec57c7ef956aea35bf3bf176f68120253846f4 Mon Sep 17 00:00:00 2001 From: "hh.jang" Date: Sat, 3 Aug 2024 10:09:53 +0900 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/spring-boot-kotlin/.idea/misc.xml | 7 ------- examples/spring-boot-kotlin/.idea/modules.xml | 8 -------- examples/spring-boot-kotlin/.idea/workspace.xml | 13 ------------- 3 files changed, 28 deletions(-) delete mode 100644 examples/spring-boot-kotlin/.idea/misc.xml delete mode 100644 examples/spring-boot-kotlin/.idea/modules.xml delete mode 100644 examples/spring-boot-kotlin/.idea/workspace.xml diff --git a/examples/spring-boot-kotlin/.idea/misc.xml b/examples/spring-boot-kotlin/.idea/misc.xml deleted file mode 100644 index acdb18a..0000000 --- a/examples/spring-boot-kotlin/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/examples/spring-boot-kotlin/.idea/modules.xml b/examples/spring-boot-kotlin/.idea/modules.xml deleted file mode 100644 index 93208ac..0000000 --- a/examples/spring-boot-kotlin/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/examples/spring-boot-kotlin/.idea/workspace.xml b/examples/spring-boot-kotlin/.idea/workspace.xml deleted file mode 100644 index 90fb901..0000000 --- a/examples/spring-boot-kotlin/.idea/workspace.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - { - "keyToString": { - "project.structure.last.edited": "Libraries", - "project.structure.proportion": "0.0", - "project.structure.side.proportion": "0.0" - } -} - \ No newline at end of file