From e4046b5c778774c1b57347869873c2658db6822f Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Fri, 28 Apr 2023 23:36:27 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=83=89=E3=83=A1=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=81=AE=E6=8A=BD=E5=87=BA=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/usbharu/hideout/domain/model/ap/JsonLd.kt | 10 +++++++++- .../service/activitypub/ActivityPubUserServiceImpl.kt | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/JsonLd.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/JsonLd.kt index 9700c9d0..f6c4c73a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/JsonLd.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/JsonLd.kt @@ -2,6 +2,7 @@ package dev.usbharu.hideout.domain.model.ap import com.fasterxml.jackson.annotation.JsonAutoDetect import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.JsonDeserializer @@ -15,7 +16,8 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize open class JsonLd { @JsonProperty("@context") @JsonDeserialize(contentUsing = ContextDeserializer::class) - @JsonSerialize(using = ContextSerializer::class) + @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY, using = ContextSerializer::class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) var context: List = emptyList() @JsonCreator @@ -57,6 +59,12 @@ class ContextDeserializer : JsonDeserializer() { } class ContextSerializer : JsonSerializer>() { + + + override fun isEmpty(value: List?): Boolean { + return value.isNullOrEmpty() + } + override fun serialize(value: List?, gen: JsonGenerator?, serializers: SerializerProvider?) { if (value.isNullOrEmpty()) { gen?.writeNull() diff --git a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserServiceImpl.kt index 4aca8b88..d63c048f 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/activitypub/ActivityPubUserServiceImpl.kt @@ -89,7 +89,7 @@ class ActivityPubUserServiceImpl( RemoteUserCreateDto( name = person.preferredUsername ?: throw IllegalActivityPubObjectException("preferredUsername is null"), - domain = url.substringAfter(":").substringBeforeLast("/"), + domain = url.substringAfter("://").substringBefore("/"), screenName = (person.name ?: person.preferredUsername) ?: throw IllegalActivityPubObjectException("preferredUsername is null"), description = person.summary ?: "", inbox = person.inbox ?: throw IllegalActivityPubObjectException("inbox is null"),