-
Notifications
You must be signed in to change notification settings - Fork 37
/
GeneratedCodeConverters.kt.mustache
39 lines (34 loc) · 1.37 KB
/
GeneratedCodeConverters.kt.mustache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package {{packageName}}.tools
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import retrofit2.Converter
import retrofit2.converter.moshi.MoshiConverterFactory
object GeneratedCodeConverters {
private val moshi = Moshi.Builder()
.add(XNullableAdapterFactory())
.add(KotlinJsonAdapterFactory())
.add(TypesAdapterFactory())
.build()
/**
* Creates everything needed for retrofit to make it work with the client lib, including a
* [Moshi] instance. If you want to use your own instance of moshi, use
* converterFactory(moshi) instead, and add [XNullableAdapterFactory], [KotlinJsonAdapterFactory] and
* [TypesAdapterFactory] to your moshi builder (in a similar way how we are instantiating the `moshi` field here).
*/
@JvmStatic
fun converterFactory(): Converter.Factory {
return WrapperConverterFactory(
CollectionFormatConverterFactory(),
EnumToValueConverterFactory(),
MoshiConverterFactory.create(moshi)
)
}
@JvmStatic
fun converterFactory(moshi: Moshi): Converter.Factory {
return WrapperConverterFactory(
CollectionFormatConverterFactory(),
EnumToValueConverterFactory(),
MoshiConverterFactory.create(moshi)
)
}
}