From 2ead9a12666d783257f5ac9171059d3439226a70 Mon Sep 17 00:00:00 2001 From: dhh Date: Tue, 22 Oct 2019 15:01:09 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++------ lib/build.gradle.kts | 2 +- lib/src/main/java/com/dhh/gson/ktx/GSON.kt | 2 +- .../src/main/java/com/dhh/gson/samples/GSONTest.kt | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index ad22b2c..5e2adc9 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,11 @@ class GSONTest { companion object { @JvmStatic fun main(args: Array) { - 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(xiaoMingJson) @@ -105,7 +105,7 @@ object GSON { inline fun fromJson(jsonElement: JsonElement): T { val type = object : TypeToken() {}.type - return gson.fromJson(jsonElement.toString(), type) + return gson.fromJson(jsonElement, type) } fun toJson(any: Any) = gson.toJson(any) diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index b20cf31..4c2df4d 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -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") diff --git a/lib/src/main/java/com/dhh/gson/ktx/GSON.kt b/lib/src/main/java/com/dhh/gson/ktx/GSON.kt index 42aefbd..8cf977f 100644 --- a/lib/src/main/java/com/dhh/gson/ktx/GSON.kt +++ b/lib/src/main/java/com/dhh/gson/ktx/GSON.kt @@ -17,7 +17,7 @@ object GSON { inline fun fromJson(jsonElement: JsonElement): T { val type = object : TypeToken() {}.type - return gson.fromJson(jsonElement.toString(), type) + return gson.fromJson(jsonElement, type) } fun toJson(any: Any) = gson.toJson(any) diff --git a/samples/src/main/java/com/dhh/gson/samples/GSONTest.kt b/samples/src/main/java/com/dhh/gson/samples/GSONTest.kt index 0a0479c..3c2ed36 100644 --- a/samples/src/main/java/com/dhh/gson/samples/GSONTest.kt +++ b/samples/src/main/java/com/dhh/gson/samples/GSONTest.kt @@ -14,11 +14,11 @@ class GSONTest { companion object { @JvmStatic fun main(args: Array) { - 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(xiaoMingJson)