-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpringBootKotlinApplication.kt
59 lines (49 loc) · 2.1 KB
/
SpringBootKotlinApplication.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.example
import com.jsoncsvbridge.factory.DefaultCsvCreatorFactory.Companion.generateCsv
import com.jsoncsvbridge.factory.DefaultCsvCreatorFactory.Companion.generateMergeCsv
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<String>) {
runApplication<SpringBootKotlinApplication>(*args)
}
@Component
class CsvCreatorRunner : CommandLineRunner {
override fun run(vararg args: String) {
val outputDir = File("csv_output").apply { mkdirs() }
val jsonOutputPath = outputDir.resolve("output_json.csv").absolutePath
val mergeJsonOutputPath = outputDir.resolve("output_merge_json.csv").absolutePath
// JSON to CSV
// 기능1. JSON 형식 문자열 CSV 파일로 변환
val jsonCreator = generateCsv("json")
// JSON to CSV
val jsonInput = """
[
{"name": "Hyunho", "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")
// 기능2. 2개 JSON 형식 문자열 CSV 파일로 변환
val mergeJsonCreator = generateMergeCsv()
val data1 = """
[
{"name": "John", "age": 30, "city": "New York", "country": "USA"}
]
"""
val data2 = """
[
{"name": "Alice", "age": 25, "city": "London", "occupation": "Engineer"},
{"name": "Bob", "age": 35, "city": "Paris", "hobby": "Photography"}
]
"""
mergeJsonCreator.createMergedCsv(data1, data2, mergeJsonOutputPath)
println("Merged 2 JSON files and converted to CSV. File saved at: $mergeJsonOutputPath")
}
}