diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt index 178373fd..6f27026e 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Undo.kt @@ -11,7 +11,7 @@ open class Undo( override val id: String, @JsonDeserialize(using = ObjectDeserializer::class) @JsonProperty("object") val apObject: Object, - val published: String + val published: String? ) : Object(add(type, "Undo")), HasId, HasActor { override fun equals(other: Any?): Boolean { @@ -21,20 +21,20 @@ open class Undo( other as Undo - if (apObject != other.apObject) return false - if (published != other.published) return false if (actor != other.actor) return false if (id != other.id) return false + if (apObject != other.apObject) return false + if (published != other.published) return false return true } override fun hashCode(): Int { var result = super.hashCode() - result = 31 * result + apObject.hashCode() - result = 31 * result + published.hashCode() result = 31 * result + actor.hashCode() result = 31 * result + id.hashCode() + result = 31 * result + apObject.hashCode() + result = 31 * result + (published?.hashCode() ?: 0) return result } @@ -43,7 +43,7 @@ open class Undo( "actor='$actor', " + "id='$id', " + "apObject=$apObject, " + - "published='$published'" + + "published=$published" + ")" + " ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt index fbe38266..48bbbfe1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/inbox/InboxJobProcessor.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.activitypub.service.inbox +import com.fasterxml.jackson.core.JsonParseException import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.activitypub.domain.model.objects.Object @@ -119,7 +120,12 @@ class InboxJobProcessor( throw IllegalStateException("ActivityPubProcessor not found. type: ${param.type}") } - val value = objectMapper.treeToValue(jsonNode, activityPubProcessor.type()) + val value = try { + objectMapper.treeToValue(jsonNode, activityPubProcessor.type()) + } catch (e: JsonParseException) { + logger.warn("Invalid JSON\n\n{}\n\n", jsonNode.toPrettyString()) + throw e + } activityPubProcessor.process(ActivityPubProcessContext(value, jsonNode, httpRequest, signature, verify)) logger.info("SUCCESS Process inbox. type: {}", param.type) diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt index ea279694..ad111d27 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/UndoTest.kt @@ -71,4 +71,25 @@ class UndoTest { val undo = ActivityPubConfig().objectMapper().readValue(json, Undo::class.java) println(undo) } + + @Test + fun MastodonのUndoのデシリアライズができる() { + //language=JSON + val json = """{ + "@context" : "https://www.w3.org/ns/activitystreams", + "id" : "https://kb.usbharu.dev/users/usbharu#follows/12/undo", + "type" : "Undo", + "actor" : "https://kb.usbharu.dev/users/usbharu", + "object" : { + "id" : "https://kb.usbharu.dev/0347b269-4dcb-4eb1-b8c4-b5f157bb6957", + "type" : "Follow", + "actor" : "https://kb.usbharu.dev/users/usbharu", + "object" : "https://test-hideout.usbharu.dev/users/testuser15" + } +}""".trimIndent() + + val undo = ActivityPubConfig().objectMapper().readValue(json, Undo::class.java) + + println(undo) + } }