Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Adopt PublishedApi #36

Merged
merged 11 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object JsonUtil {
null
}

fun <T> fromJson(
inline fun <reified T> fromJson(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is reified there really needed?

@Language("JSON") string: String,
rawType: Class<*>,
vararg typeArguments: Class<*>
Expand Down
15 changes: 8 additions & 7 deletions common/src/test/kotlin/io/goooler/demoapp/common/JsonUtilTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.goooler.demoapp.common

import com.squareup.moshi.JsonClass
import io.goooler.demoapp.base.util.secondOrNull
import io.goooler.demoapp.common.util.JsonUtil
import io.goooler.demoapp.common.util.fromJson
import io.goooler.demoapp.common.util.toJson
Expand All @@ -17,10 +18,10 @@ class JsonUtilTest {

@Test
fun `JsonUtil fromJson(String, Class, Class)`() {
val array: List<Repo> = JsonUtil.fromJson(strArray, List::class.java, Repo::class.java)
val list: List<Repo> = JsonUtil.fromJson(strArray, List::class.java, Repo::class.java)
?: throw Exception("Parse json error")
assertTrue(array.first() == firstBean)
assertTrue(array[1] == secondBean)
assertTrue(list.firstOrNull() == firstBean)
assertTrue(list.secondOrNull() == secondBean)
}

@Test
Expand All @@ -37,14 +38,14 @@ class JsonUtilTest {

@Test
fun `String fromJson(Class, Class)`() {
val array: List<Repo> = strArray.fromJson(List::class.java, Repo::class.java)
val list: List<Repo> = strArray.fromJson(List::class.java, Repo::class.java)
?: throw Exception("Parse json error")
assertTrue(array.first() == firstBean)
assertTrue(array[1] == secondBean)
assertTrue(list.first() == firstBean)
assertTrue(list[1] == secondBean)
}

@Test
fun `Any? toJson(T)`() {
fun `Any toJson(T)`() {
assertTrue(firstBean.toJson() == firstStr)
assertTrue(secondBean.toJson() == secondStr)
}
Expand Down