mathew murphy
07/17/2019, 4:08 PMmoshi
variable knows about BlackjackHand
and has an adapter for it. I can't call moshi.adapter
until I have called .build()
, and once I've called .build()
I can't work out how to add another adapter to the set.Giorgos Neokleous
07/17/2019, 4:55 PMmoshi.newBuilder().
would domathew murphy
07/17/2019, 5:15 PMmathew murphy
07/17/2019, 5:23 PMjava.lang.IllegalArgumentException: Platform class java.math.BigDecimal (with no annotations) requires explicit JsonAdapter to be registered
mathew murphy
07/17/2019, 5:23 PMmathew murphy
07/17/2019, 5:25 PMjava.lang.IllegalArgumentException: Expected at least one @ToJson or @FromJson method on com.squareup.moshi.JsonAdapter$2
mbonnin
07/17/2019, 5:54 PM@ToJson
or @FromJson
method. https://github.com/square/moshi#custom-type-adaptersmathew murphy
07/17/2019, 6:16 PMmbonnin
07/17/2019, 6:18 PMmbonnin
07/17/2019, 6:18 PMmbonnin
07/17/2019, 6:19 PMmathew murphy
07/17/2019, 6:19 PMmathew murphy
07/17/2019, 6:20 PMmbonnin
07/17/2019, 6:21 PMBlackjackHand
contain BigDecimal
?mathew murphy
07/17/2019, 6:21 PMmbonnin
07/17/2019, 6:23 PMmathew murphy
07/17/2019, 6:23 PMmbonnin
07/17/2019, 6:23 PMmbonnin
07/17/2019, 6:23 PMmathew murphy
07/17/2019, 6:23 PMmathew murphy
07/17/2019, 6:24 PMmosh = moshi.newBuilder().add(...).build()
seems to lose all the adapters that were in moshi already.mbonnin
07/17/2019, 6:24 PMmosh.newBuilder.add(jsonAdapter)
, the jsonAdapter is an instance here, right ?mbonnin
07/17/2019, 6:25 PMmathew murphy
07/17/2019, 6:25 PMmbonnin
07/17/2019, 6:26 PMmathew murphy
07/17/2019, 6:26 PMmbonnin
07/17/2019, 6:26 PMmathew murphy
07/17/2019, 6:27 PMmbonnin
07/17/2019, 6:27 PMmathew murphy
07/17/2019, 6:28 PMmoshi.adapter
, and an example of using a custom class with @To/FromJson annotations, but it doesn't give an example of both.mbonnin
07/17/2019, 6:28 PMjsonAdapter
to your moshiBuildermbonnin
07/17/2019, 6:29 PMmbonnin
07/17/2019, 6:30 PMval moshi = Moshi.Builder()
.add(ZonedDateTimeAdapter)
.add(BigDecimalAdapter)
.add(KotlinJsonAdaptorFactory())
.build()
val jsonAdapter = moshi.adapter(BlackjackHand::class.java);
String json = jsonAdapter.toJson(blackjackHand);
mathew murphy
07/17/2019, 6:48 PMmathew murphy
07/17/2019, 6:48 PMmathew murphy
07/17/2019, 6:50 PMmbonnin
07/17/2019, 6:51 PMmoshi.newBuilder().add(jsonAdapter)
👈 Don't do thismathew murphy
07/17/2019, 6:52 PMmbonnin
07/17/2019, 6:53 PMmbonnin
07/17/2019, 6:54 PMvar moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.add(BigDecimalAdapter)
.build()
val obj = Bet(BigDecimal.TEN, BlackjackHand("4H 10D"))
println(moshi.adapter(Bet::class.java).toJson(obj))
mbonnin
07/17/2019, 6:55 PMmathew murphy
07/17/2019, 6:57 PMmoshi.adapter()
, that adapter is available to the Moshi instance without having to explicitly add it?mbonnin
07/17/2019, 6:59 PMmbonnin
07/17/2019, 7:00 PMKotlinJsonAdapterFactory
magicmathew murphy
07/17/2019, 7:04 PMmbonnin
07/17/2019, 7:07 PMmbonnin
07/17/2019, 7:08 PMmathew murphy
07/17/2019, 7:09 PM.add
, rather it's telling Moshi the full type signature so that it can then construct what it needs to serialize/deserialize.mbonnin
07/17/2019, 7:10 PMmathew murphy
07/17/2019, 7:14 PMmathew murphy
07/17/2019, 7:15 PMmathew murphy
07/17/2019, 7:16 PMmbonnin
07/17/2019, 7:18 PMmbonnin
07/17/2019, 7:18 PMmbonnin
07/17/2019, 7:19 PMmathew murphy
07/17/2019, 7:19 PMmbonnin
07/17/2019, 7:20 PMmathew murphy
07/17/2019, 7:21 PMmathew murphy
07/17/2019, 7:21 PMmathew murphy
07/17/2019, 7:21 PMmathew murphy
07/17/2019, 7:27 PMw: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
/home/meta/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.3.40/2d1d0a2f27fd060787075c69113846803fc27734/kotlin-stdlib-jdk8-1.3.40.jar (version 1.3)
/home/meta/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.40/2995de8f68444ad47f29e7b59962ac31e6301d7e/kotlin-stdlib-jdk7-1.3.40.jar (version 1.3)
/home/meta/.gradle/caches/modules-2/files-2.1/me.eugeniomarletti.kotlin.metadata/kotlin-compiler-lite/1.0.3-k-1.2.40/a16e967c276379eaf6e1fa03af77664f003db947/kotlin-compiler-lite-1.0.3-k-1.2.40.jar (version 1.2)
/home/meta/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.40/b8a521c687329303778548e2f09b0ba5b2665236/kotlin-stdlib-1.3.40.jar (version 1.3)
/home/meta/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.40/ff8f3da514fc2877d1303d55e22d6da8156c29fb/kotlin-stdlib-common-1.3.40.jar (version 1.3)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
mathew murphy
07/17/2019, 7:28 PMmbonnin
07/17/2019, 7:31 PMmbonnin
07/17/2019, 7:31 PMmathew murphy
07/17/2019, 7:41 PMmathew murphy
07/17/2019, 7:43 PMDico
07/17/2019, 10:18 PMjdk7
is a transitive dependency of jdk8