@@ -33,23 +33,6 @@ import org.http4k.format.asConfigurable
3333import org.http4k.format.withStandardMappings
3434
3535internal lateinit var moshiReVoman: Moshi
36- private val moshiBuilder: Moshi .Builder =
37- Moshi .Builder ()
38- .add(JsonString .Factory ())
39- .add(AdaptedBy .Factory ())
40- .add(TypeAdapter )
41- .add(BigDecimalAdapter )
42- .add(UUIDAdapter )
43- .add(EpochAdapter )
44- .add(Date ::class .java, Rfc3339DateJsonAdapter ())
45- .addLast(CaseInsensitiveEnumAdapter .FACTORY )
46- .addLast(EventAdapter )
47- .addLast(ThrowableAdapter )
48- .addLast(ListAdapter )
49- .addLast(MapAdapter )
50- .asConfigurable()
51- .withStandardMappings()
52- .done()
5336
5437@JvmOverloads
5538internal fun initMoshi (
@@ -68,6 +51,25 @@ internal fun buildMoshi(
6851 customAdaptersWithType : Map <Type , List <Either <JsonAdapter <Any >, Factory >>> = emptyMap(),
6952 typesToIgnore : Set <Class <out Any >> = emptySet()
7053): Moshi .Builder {
54+ // * NOTE 08 May 2024 gopala.akshintala: This cannot be static singleton as adapters added mutates
55+ // the singleton
56+ val moshiBuilder =
57+ Moshi .Builder ()
58+ .add(JsonString .Factory ())
59+ .add(AdaptedBy .Factory ())
60+ .add(TypeAdapter )
61+ .add(BigDecimalAdapter )
62+ .add(UUIDAdapter )
63+ .add(EpochAdapter )
64+ .add(Date ::class .java, Rfc3339DateJsonAdapter ())
65+ .addLast(CaseInsensitiveEnumAdapter .FACTORY )
66+ .addLast(EventAdapter )
67+ .addLast(ThrowableAdapter )
68+ .addLast(ListAdapter )
69+ .addLast(MapAdapter )
70+ .asConfigurable()
71+ .withStandardMappings()
72+ .done()
7173 customAdaptersWithType.forEach { (type, customAdapters) ->
7274 customAdapters.forEach { customAdapter ->
7375 customAdapter.fold({ moshiBuilder.add(type, it) }, { moshiBuilder.add(it) })
0 commit comments