Last active
September 20, 2023 01:26
-
-
Save Arham4/429ee1216e0d7224cb1522ac5a2a0fe2 to your computer and use it in GitHub Desktop.
Revisions
-
Arham4 revised this gist
Feb 9, 2021 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,9 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import java.nio.file.Path val mapper = jacksonObjectMapper() data class UserDto(val username: String, val password: String) -
Arham4 revised this gist
Jan 31, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import java.nio.file.Path // Extension function taking in Path as a parameter for ease of use inline fun <reified T> ObjectMapper.readValue(src: Path): T = readValue(src.toFile()) -
Arham4 revised this gist
Jan 31, 2021 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.nio.file.Path // Extension function taking in Path as a parameter for ease of use inline fun <reified T> ObjectMapper.readValue(src: Path): T = readValue(src.toFile(), jacksonTypeRef<T>()) -
Arham4 revised this gist
Jan 31, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,7 @@ val mapper = ObjectMapper() .registerKotlinModule() data class UserDto(val username: String, val password: String) val user: UserDto = mapper.readValue(Path.of("data.yml").toFile()) // or, using the below extension function: val user: UserDto = mapper.readValue(Path.of("data.yml")) -
Arham4 revised this gist
Jan 31, 2021 . 2 changed files with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,4 +7,6 @@ val mapper = ObjectMapper() .registerKotlinModule() data class UserDto(val username: String, val password: String) val user: UserDto = mapper.readValue(Path.of("data.yml").toFile()) // or, using the below extension function: val user: UserDto = mapper.readValue(Path.of("data.yml")) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ // Extension function taking in Path as a parameter for ease of use inline fun <reified T> ObjectMapper.readValue(src: Path): T = readValue(src.toFile(), jacksonTypeRef<T>()) -
Arham4 revised this gist
Jan 31, 2021 . 3 changed files with 3 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,2 @@ username: "Test" password: "123456" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,10 +6,5 @@ import java.nio.file.Path val mapper = ObjectMapper() .registerKotlinModule() data class UserDto(val username: String, val password: String) val user: UserDto = mapper.readValue(Path.of("data.yml").toFile()) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +0,0 @@ -
Arham4 revised this gist
Jan 31, 2021 . 2 changed files with 1 addition and 1 deletion.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,2 @@ data class UserDto(val username: String, val password: String) val user: UserDto = parseDto<UserDto>("data.yaml") -
Arham4 renamed this gist
Jan 31, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Arham4 revised this gist
Jan 31, 2021 . 3 changed files with 13 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,15 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.registerKotlinModule import java.nio.file.Path val mapper = ObjectMapper() .registerKotlinModule() /** * Takes in a data class via generics and parses it by the fileName provided, returning the class * provided with parsed data. */ inline fun <reified T> parseDto(fileName: String): T { return mapper.readValue(Path.of(fileName).toFile()) } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,2 @@ data class UserDto(val username: String, val password: String) val user: UserDto = parseDto<UserDto>("user.yaml") This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,2 @@ username: "Test" password: 123456 -
Arham4 revised this gist
Jan 10, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,5 +7,5 @@ private val mapper = ObjectMapper(YAMLFactory()) * originally provided with parsed data. */ fun <T: Any> parseDto(fileName: String, dto: KClass<T>): T { return Files.newBufferedReader(Paths.get(fileName)).use { mapper.readValue(it, dto.java) } } -
Arham4 revised this gist
Jan 10, 2021 . 3 changed files with 11 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,11 @@ private val mapper = ObjectMapper(YAMLFactory()) .registerModule(KotlinModule()) .configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) /** * Takes in a data class (with ::class) and parses it by the fileName provided, returning the appropriate class * originally provided with parsed data. */ fun <T: Any> parseDto(fileName: String, dto: KClass<T>): T { return Files.newBufferedReader(FileSystems.getDefault().getPath(fileName)).use { mapper.readValue(it, dto.java) } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ data class UserDto(val username: String, val password: String) val user: UserDto = parseDto("user.yaml", UserDto::class) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +0,0 @@ -
Arham4 revised this gist
Apr 26, 2020 . 2 changed files with 3 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,10 +13,4 @@ object YAMLParse { fun <T: Any> parseDto(fileName: String, dto: KClass<T>): T { return Files.newBufferedReader(FileSystems.getDefault().getPath(fileName)).use { mapper.readValue(it, dto.java) } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ data class UserDto(val username: String, val password: String) val user: UserDto = YAMLParse.parseDto("user.yaml", UserDto::class) -
Arham4 revised this gist
Feb 4, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ username: Test # don't need "" because of configuration password: 123456 -
Arham4 revised this gist
Feb 4, 2018 . No changes.There are no files selected for viewing
-
Arham4 created this gist
Feb 4, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ object YAMLParse { private val mapper = let { val mapper = ObjectMapper(YAMLFactory()) mapper.registerModule(KotlinModule()) mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) mapper } /** * Takes in a data class (with ::class) and parses it by the fileName provided, returning the appropriate class * originally provided with parsed data. */ fun <T: Any> parseDto(fileName: String, dto: KClass<T>): T { return Files.newBufferedReader(FileSystems.getDefault().getPath(fileName)).use { mapper.readValue(it, dto.java) } } } /** * Usage: */ data class UserDto(val username: String, val password: String) val user: UserDto = YAMLParse.parseDto("user.yaml", UserDto::class)