File tree 1 file changed +4
-0
lines changed
src/main/kotlin/com/mazenrashed/moshikotlinextensions
1 file changed +4
-0
lines changed Original file line number Diff line number Diff line change 1
1
package com.mazenrashed.moshikotlinextensions
2
2
3
3
import com.squareup.moshi.JsonAdapter
4
+ import com.squareup.moshi.JsonDataException
4
5
import com.squareup.moshi.Moshi
5
6
import com.squareup.moshi.Types
6
7
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
8
+ import kotlin.jvm.Throws
7
9
8
10
object MoshiExtensions {
9
11
var moshi: Moshi = Moshi .Builder ()
@@ -15,11 +17,13 @@ object MoshiExtensions {
15
17
}
16
18
}
17
19
20
+ @Throws(JsonDataException ::class )
18
21
inline fun <reified T > String.deserialize (): T ? {
19
22
val jsonAdapter = MoshiExtensions .moshi.adapter(T ::class .java)
20
23
return jsonAdapter.fromJson(this )
21
24
}
22
25
26
+ @Throws(JsonDataException ::class )
23
27
inline fun <reified T > String.deserializeList (): List <T >? {
24
28
val type = Types .newParameterizedType(MutableList ::class .java, T ::class .java)
25
29
val jsonAdapter: JsonAdapter <List <T >> = MoshiExtensions .moshi.adapter(type)
You can’t perform that action at this time.
0 commit comments