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

Commit

Permalink
simplify adapter factory
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddenton committed Jan 9, 2021
1 parent 1c11479 commit 70fe550
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import java.lang.reflect.Type
abstract class ConnectJsonAdapterFactory(vararg typesToAdapters: Pair<String, (Moshi) -> JsonAdapter<*>>) : JsonAdapter.Factory {
private val mappings = typesToAdapters.toMap()

override fun create(type: Type, annotations: Set<Annotation>, moshi: Moshi) = when {
annotations.isNotEmpty() -> null
else -> mappings[Types.getRawType(type).typeName]?.let { it(moshi) }
}
override fun create(type: Type, annotations: Set<Annotation>, moshi: Moshi) =
mappings[Types.getRawType(type).typeName]?.let { it(moshi) }
}

inline fun <reified T : JsonAdapter<K>, reified K> adapter(noinline fn: (Moshi) -> T) = K::class.java.name to fn

0 comments on commit 70fe550

Please sign in to comment.