Skip to content

Commit

Permalink
♻️ refactor api
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Oct 22, 2019
1 parent f43004a commit 2ead9a1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class GSONTest {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val xiaoMingJson = """{name:"XiaoMing",age:22}"""
val xiaoLiJson = """{name:"XiaoLi",age:20}"""
val classJson = """[$xiaoLiJson,$xiaoMingJson]"""
val studentMapJson = """{xiaoMing:$xiaoMingJson,xiaoLi:$xiaoLiJson}"""
val classMapJson = """{class1:$classJson,class2:$classJson}"""
val xiaoMingJson = """{"name":"XiaoMing","age":22}"""
val xiaoLiJson = """{"name":"XiaoLi","age":20}"""
val classJson = """[$xiaoLiJson,$xiaoMingJson]"""
val studentMapJson = """{"xiaoMing":$xiaoMingJson,"xiaoLi":$xiaoLiJson}"""
val classMapJson = """{"class1":$classJson,"class2":$classJson}"""


val xiaoMing: Student = GSON.fromJson<Student>(xiaoMingJson)
Expand Down Expand Up @@ -105,7 +105,7 @@ object GSON {

inline fun <reified T> fromJson(jsonElement: JsonElement): T {
val type = object : TypeToken<T>() {}.type
return gson.fromJson(jsonElement.toString(), type)
return gson.fromJson(jsonElement, type)
}

fun toJson(any: Any) = gson.toJson(any)
Expand Down
2 changes: 1 addition & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ publish {
userOrg = "dhhandroid"
groupId = "com.dhh"
artifactId = "gson-ktx"
publishVersion = "1.0.2"
publishVersion = "1.0.3"
desc = "A set of Kotlin extensions for Gson"
website = "https://github.com/dhhAndroid/gson-ktx"
bintrayUser = loadProperties.getProperty("bintray.user")
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/com/dhh/gson/ktx/GSON.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object GSON {

inline fun <reified T> fromJson(jsonElement: JsonElement): T {
val type = object : TypeToken<T>() {}.type
return gson.fromJson(jsonElement.toString(), type)
return gson.fromJson(jsonElement, type)
}

fun toJson(any: Any) = gson.toJson(any)
Expand Down
8 changes: 4 additions & 4 deletions samples/src/main/java/com/dhh/gson/samples/GSONTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class GSONTest {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val xiaoMingJson = """{name:"XiaoMing",age:22}"""
val xiaoLiJson = """{name:"XiaoLi",age:20}"""
val xiaoMingJson = """{"name":"XiaoMing","age":22}"""
val xiaoLiJson = """{"name":"XiaoLi","age":20}"""
val classJson = """[$xiaoLiJson,$xiaoMingJson]"""
val studentMapJson = """{xiaoMing:$xiaoMingJson,xiaoLi:$xiaoLiJson}"""
val classMapJson = """{class1:$classJson,class2:$classJson}"""
val studentMapJson = """{"xiaoMing":$xiaoMingJson,"xiaoLi":$xiaoLiJson}"""
val classMapJson = """{"class1":$classJson,"class2":$classJson}"""


val xiaoMing = GSON.fromJson<Student>(xiaoMingJson)
Expand Down

0 comments on commit 2ead9a1

Please sign in to comment.