Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nesting Problem when sending messages with attachment #265

Open
GJKrupa opened this issue Nov 7, 2019 · 1 comment
Open

Nesting Problem when sending messages with attachment #265

GJKrupa opened this issue Nov 7, 2019 · 1 comment

Comments

@GJKrupa
Copy link

GJKrupa commented Nov 7, 2019

Using v3.5.1, I'm sending a message after connection using the following Kotlin code:

                client.chatRooms().update.find { it.name == "bot-test" }?.id?.also {
                    client.sendMessage(
                        UUID.randomUUID().toString(),
                        roomId = it,
                        message = "[BOT] Connnected",
                        emoji = ":robot:",
                        alias = "bot",
                        attachments = listOf(Attachment("Hello"))
                    )
                }

This fails with the following exception from Moshi:

Exception in thread "DefaultDispatcher-worker-2" java.lang.IllegalStateException: Nesting problem.
	at com.squareup.moshi.JsonUtf8Writer.close(JsonUtf8Writer.java:133)
	at com.squareup.moshi.JsonUtf8Writer.endArray(JsonUtf8Writer.java:90)
	at com.squareup.moshi.CollectionJsonAdapter.toJson(CollectionJsonAdapter.java:87)
	at com.squareup.moshi.CollectionJsonAdapter$2.toJson(CollectionJsonAdapter.java:53)
	at com.squareup.moshi.JsonAdapter$2.toJson(JsonAdapter.java:144)
	at chat.rocket.core.internal.model.KotshiSendMessageBodyJsonAdapter.toJson(KotshiSendMessageBodyJsonAdapter.java:59)
	at chat.rocket.core.internal.model.KotshiSendMessageBodyJsonAdapter.toJson(KotshiSendMessageBodyJsonAdapter.java:19)
	at com.squareup.moshi.ClassJsonAdapter$FieldBinding.write(ClassJsonAdapter.java:201)
	at com.squareup.moshi.ClassJsonAdapter.toJson(ClassJsonAdapter.java:170)
	at com.squareup.moshi.JsonAdapter$2.toJson(JsonAdapter.java:144)
	at com.squareup.moshi.JsonAdapter.toJson(JsonAdapter.java:52)
	at com.squareup.moshi.JsonAdapter.toJson(JsonAdapter.java:58)
	at chat.rocket.core.internal.rest.MessageKt$sendMessage$2.invokeSuspend(Message.kt:53)
	at chat.rocket.core.internal.rest.MessageKt$sendMessage$2.invoke(Message.kt)
	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:91)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:146)
	at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
	at chat.rocket.core.internal.rest.MessageKt.sendMessage(Message.kt:48)
	at chat.rocket.core.internal.rest.MessageKt.sendMessage$default(Message.kt:47)
	at uk.gov.homeoffice.themis.connectors.RocketChat$chatClient$job$1$1.invokeSuspend(RocketChat.kt:63)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)

As this is a bot rather than an Android app, I'm also importing org.json:json:20190722

@GJKrupa
Copy link
Author

GJKrupa commented Feb 2, 2021

This appears to be due to a missing call to endObject() in AttachmentAdapter.toJson()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant