org.http4k.format.Moshi.kt Maven / Gradle / Ivy
package org.http4k.format
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
fun standardConfig(kotlinFactory: JsonAdapter.Factory = KotlinJsonAdapterFactory()) = Moshi.Builder()
.addLast(EventAdapter)
.addLast(ThrowableAdapter)
.addLast(ListAdapter)
.addLast(SetAdapter)
.addLast(MapAdapter)
.addLast(MoshiNodeAdapter)
.asConfigurable(kotlinFactory)
.withStandardMappings()
/**
* To implement custom JSON configuration, create your own object singleton. Extra mappings can be added before done() is called.
*/
object Moshi : ConfigurableMoshi(standardConfig().done()) {
fun custom(configureFn: AutoMappingConfiguration.() -> AutoMappingConfiguration) =
ConfigurableMoshi(standardConfig().let(configureFn).done())
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy