refactor: Objectを継承するJSONマッピング用のPOJOをNull-safeに

This commit is contained in:
usbharu 2023-11-28 11:19:27 +09:00
parent 6c2d5dae94
commit 7a34b11147
18 changed files with 258 additions and 231 deletions

View File

@ -1,41 +1,46 @@
package dev.usbharu.hideout.activitypub.domain.model package dev.usbharu.hideout.activitypub.domain.model
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer
open class Accept : Object { open class Accept @JsonCreator constructor(
type: List<String> = emptyList(),
override val name: String,
@JsonDeserialize(using = ObjectDeserializer::class) @JsonDeserialize(using = ObjectDeserializer::class)
@Suppress("VariableNaming") @Suppress("VariableNaming")
var `object`: Object? = null var `object`: Object?,
override val actor: String
protected constructor() ) : Object(
constructor( type = add(type, "Accept")
type: List<String> = emptyList(), ),
name: String, HasActor,
`object`: Object?, HasName {
actor: String?
) : super(
type = add(type, "Accept"),
name = name,
actor = actor
) {
this.`object` = `object`
}
override fun toString(): String = "Accept(`object`=$`object`) ${super.toString()}"
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Accept) return false if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false if (!super.equals(other)) return false
return `object` == other.`object` other as Accept
if (`object` != other.`object`) return false
if (actor != other.actor) return false
if (name != other.name) return false
return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + (`object`?.hashCode() ?: 0) result = 31 * result + (`object`?.hashCode() ?: 0)
result = 31 * result + actor.hashCode()
result = 31 * result + name.hashCode()
return result return result
} }
override fun toString(): String {
return "Accept(" + "`object`=$`object`, " + "actor='$actor', " + "name='$name'" + ")" + " ${super.toString()}"
}
} }

View File

@ -4,46 +4,51 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer
open class Create : Object { open class Create(
type: List<String> = emptyList(),
override val name: String,
@JsonDeserialize(using = ObjectDeserializer::class) @JsonDeserialize(using = ObjectDeserializer::class)
@Suppress("VariableNaming") @Suppress("VariableNaming")
var `object`: Object? = null var `object`: Object?,
var to: List<String> = emptyList() override val actor: String,
override val id: String,
var to: List<String> = emptyList(),
var cc: List<String> = emptyList() var cc: List<String> = emptyList()
) : Object(
protected constructor() : super() type = add(type, "Create")
constructor( ),
type: List<String> = emptyList(), HasId,
name: String? = null, HasName,
`object`: Object?, HasActor {
actor: String? = null,
id: String? = null,
to: List<String> = emptyList(),
cc: List<String> = emptyList()
) : super(
type = add(type, "Create"),
name = name,
actor = actor,
id = id
) {
this.`object` = `object`
this.to = to
this.cc = cc
}
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Create) return false if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false if (!super.equals(other)) return false
return `object` == other.`object` other as Create
if (`object` != other.`object`) return false
if (to != other.to) return false
if (cc != other.cc) return false
if (name != other.name) return false
if (actor != other.actor) return false
if (id != other.id) return false
return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + (`object`?.hashCode() ?: 0) result = 31 * result + (`object`?.hashCode() ?: 0)
result = 31 * result + to.hashCode()
result = 31 * result + cc.hashCode()
result = 31 * result + name.hashCode()
result = 31 * result + actor.hashCode()
result = 31 * result + id.hashCode()
return result return result
} }
override fun toString(): String = "Create(`object`=$`object`) ${super.toString()}" override fun toString(): String =
"Create(`object`=$`object`, to=$to, cc=$cc, name='$name', actor='$actor', id='$id') ${super.toString()}"
} }

View File

@ -4,33 +4,42 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer
open class Delete : Object { open class Delete : Object, HasId, HasActor, HasName {
@JsonDeserialize(using = ObjectDeserializer::class) @JsonDeserialize(using = ObjectDeserializer::class)
@Suppress("VariableNaming") @Suppress("VariableNaming")
var `object`: Object? = null var `object`: Object? = null
var published: String? = null var published: String? = null
override val actor: String
override val id: String
override val name: String
constructor( constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
name: String? = "Delete", name: String = "Delete",
actor: String, actor: String,
id: String, id: String,
`object`: Object, `object`: Object,
published: String? published: String?
) : super(add(type, "Delete"), name, actor, id) { ) : super(add(type, "Delete")) {
this.`object` = `object` this.`object` = `object`
this.published = published this.published = published
this.name = name
this.actor = actor
this.id = id
} }
protected constructor() : super()
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Delete) return false if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false if (!super.equals(other)) return false
other as Delete
if (`object` != other.`object`) return false if (`object` != other.`object`) return false
if (published != other.published) return false if (published != other.published) return false
if (actor != other.actor) return false
if (id != other.id) return false
if (name != other.name) return false
return true return true
} }
@ -39,8 +48,12 @@ open class Delete : Object {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + (`object`?.hashCode() ?: 0) result = 31 * result + (`object`?.hashCode() ?: 0)
result = 31 * result + (published?.hashCode() ?: 0) result = 31 * result + (published?.hashCode() ?: 0)
result = 31 * result + actor.hashCode()
result = 31 * result + id.hashCode()
result = 31 * result + name.hashCode()
return result return result
} }
override fun toString(): String = "Delete(`object`=$`object`, published=$published) ${super.toString()}" override fun toString(): String =
"Delete(`object`=$`object`, published=$published, actor='$actor', id='$id', name='$name') ${super.toString()}"
} }

View File

@ -2,34 +2,35 @@ package dev.usbharu.hideout.activitypub.domain.model
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
open class Document : Object { open class Document : Object, HasName {
var mediaType: String? = null var mediaType: String? = null
var url: String? = null var url: String? = null
override val name: String
protected constructor() : super()
constructor( constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
name: String? = null, name: String,
mediaType: String, mediaType: String,
url: String url: String
) : super( ) : super(
type = add(type, "Document"), type = add(type, "Document")
name = name,
actor = null,
id = null
) { ) {
this.mediaType = mediaType this.mediaType = mediaType
this.url = url this.url = url
this.name = name
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Document) return false if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false if (!super.equals(other)) return false
other as Document
if (mediaType != other.mediaType) return false if (mediaType != other.mediaType) return false
if (url != other.url) return false if (url != other.url) return false
if (name != other.name) return false
return true return true
} }
@ -38,8 +39,9 @@ open class Document : Object {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + (mediaType?.hashCode() ?: 0) result = 31 * result + (mediaType?.hashCode() ?: 0)
result = 31 * result + (url?.hashCode() ?: 0) result = 31 * result + (url?.hashCode() ?: 0)
result = 31 * result + name.hashCode()
return result return result
} }
override fun toString(): String = "Document(mediaType=$mediaType, url=$url) ${super.toString()}" override fun toString(): String = "Document(mediaType=$mediaType, url=$url, name='$name') ${super.toString()}"
} }

View File

@ -15,10 +15,7 @@ open class Emoji : Object {
updated: String?, updated: String?,
icon: Image? icon: Image?
) : super( ) : super(
type = add(type, "Emoji"), type = add(type, "Emoji")
name = name,
actor = actor,
id = id
) { ) {
this.updated = updated this.updated = updated
this.icon = icon this.icon = icon

View File

@ -2,37 +2,42 @@ package dev.usbharu.hideout.activitypub.domain.model
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
open class Follow : Object { open class Follow : Object, HasActor {
@Suppress("VariableNaming") @Suppress("VariableNaming")
var `object`: String? = null var `object`: String? = null
protected constructor() : super() override val actor: String
constructor( constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
name: String?,
`object`: String?, `object`: String?,
actor: String? actor: String
) : super( ) : super(
type = add(type, "Follow"), type = add(type, "Follow")
name = name,
actor = actor
) { ) {
this.`object` = `object` this.`object` = `object`
this.actor = actor
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Follow) return false if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false if (!super.equals(other)) return false
return `object` == other.`object` other as Follow
if (`object` != other.`object`) return false
if (actor != other.actor) return false
return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + (`object`?.hashCode() ?: 0) result = 31 * result + (`object`?.hashCode() ?: 0)
result = 31 * result + actor.hashCode()
return result return result
} }
override fun toString(): String = "Follow(`object`=$`object`) ${super.toString()}" override fun toString(): String = "Follow(`object`=$`object`, actor='$actor') ${super.toString()}"
} }

View File

@ -0,0 +1,5 @@
package dev.usbharu.hideout.activitypub.domain.model
interface HasActor {
val actor: String
}

View File

@ -0,0 +1,5 @@
package dev.usbharu.hideout.activitypub.domain.model
interface HasId {
val id: String
}

View File

@ -0,0 +1,5 @@
package dev.usbharu.hideout.activitypub.domain.model
interface HasName {
val name: String
}

View File

@ -7,9 +7,8 @@ open class Image : Object {
private var url: String? = null private var url: String? = null
protected constructor() : super() protected constructor() : super()
constructor(type: List<String> = emptyList(), name: String, mediaType: String?, url: String?) : super( constructor(type: List<String> = emptyList(), mediaType: String?, url: String?) : super(
add(type, "Image"), add(type, "Image")
name
) { ) {
this.mediaType = mediaType this.mediaType = mediaType
this.url = url this.url = url
@ -17,11 +16,15 @@ open class Image : Object {
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Image) return false if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false if (!super.equals(other)) return false
other as Image
if (mediaType != other.mediaType) return false if (mediaType != other.mediaType) return false
return url == other.url if (url != other.url) return false
return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {
@ -30,4 +33,6 @@ open class Image : Object {
result = 31 * result + (url?.hashCode() ?: 0) result = 31 * result + (url?.hashCode() ?: 0)
return result return result
} }
override fun toString(): String = "Image(mediaType=$mediaType, url=$url) ${super.toString()}"
} }

View File

@ -2,41 +2,45 @@ package dev.usbharu.hideout.activitypub.domain.model
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
open class Key : Object { open class Key : Object, HasId {
var owner: String? = null var owner: String? = null
var publicKeyPem: String? = null var publicKeyPem: String? = null
override val id: String
protected constructor() : super()
constructor( constructor(
type: List<String>, type: List<String>,
name: String,
id: String, id: String,
owner: String?, owner: String?,
publicKeyPem: String? publicKeyPem: String?
) : super( ) : super(
type = add(list = type, type = "Key"), type = add(list = type, type = "Key")
name = name,
id = id
) { ) {
this.owner = owner this.owner = owner
this.publicKeyPem = publicKeyPem this.publicKeyPem = publicKeyPem
this.id = id
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Key) return false if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false if (!super.equals(other)) return false
other as Key
if (owner != other.owner) return false if (owner != other.owner) return false
return publicKeyPem == other.publicKeyPem if (publicKeyPem != other.publicKeyPem) return false
if (id != other.id) return false
return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + (owner?.hashCode() ?: 0) result = 31 * result + (owner?.hashCode() ?: 0)
result = 31 * result + (publicKeyPem?.hashCode() ?: 0) result = 31 * result + (publicKeyPem?.hashCode() ?: 0)
result = 31 * result + id.hashCode()
return result return result
} }
override fun toString(): String = "Key(owner=$owner, publicKeyPem=$publicKeyPem) ${super.toString()}" override fun toString(): String = "Key(owner=$owner, publicKeyPem=$publicKeyPem, id='$id') ${super.toString()}"
} }

View File

@ -4,42 +4,47 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer
open class Like : Object { open class Like : Object, HasId, HasActor {
@Suppress("VariableNaming") @Suppress("VariableNaming")
var `object`: String? = null var `object`: String? = null
var content: String? = null var content: String? = null
@JsonDeserialize(contentUsing = ObjectDeserializer::class) @JsonDeserialize(contentUsing = ObjectDeserializer::class)
var tag: List<Object> = emptyList() var tag: List<Object> = emptyList()
override val actor: String
override val id: String
protected constructor() : super()
constructor( constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
name: String?, actor: String,
actor: String?, id: String,
id: String?,
`object`: String?, `object`: String?,
content: String?, content: String?,
tag: List<Object> = emptyList() tag: List<Object> = emptyList()
) : super( ) : super(
type = add(type, "Like"), type = add(type, "Like")
name = name,
actor = actor,
id = id
) { ) {
this.`object` = `object` this.`object` = `object`
this.content = content this.content = content
this.tag = tag this.tag = tag
this.actor = actor
this.id = id
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Like) return false if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false if (!super.equals(other)) return false
other as Like
if (`object` != other.`object`) return false if (`object` != other.`object`) return false
if (content != other.content) return false if (content != other.content) return false
return tag == other.tag if (tag != other.tag) return false
if (actor != other.actor) return false
if (id != other.id) return false
return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {
@ -47,8 +52,12 @@ open class Like : Object {
result = 31 * result + (`object`?.hashCode() ?: 0) result = 31 * result + (`object`?.hashCode() ?: 0)
result = 31 * result + (content?.hashCode() ?: 0) result = 31 * result + (content?.hashCode() ?: 0)
result = 31 * result + tag.hashCode() result = 31 * result + tag.hashCode()
result = 31 * result + actor.hashCode()
result = 31 * result + id.hashCode()
return result return result
} }
override fun toString(): String = "Like(`object`=$`object`, content=$content, tag=$tag) ${super.toString()}" override fun toString(): String {
return "Like(`object`=$`object`, content=$content, tag=$tag, actor='$actor', id='$id') ${super.toString()}"
}
} }

View File

@ -2,79 +2,58 @@ package dev.usbharu.hideout.activitypub.domain.model
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
open class Note : Object { open class Note
lateinit var attributedTo: String @Suppress("LongParameterList")
var attachment: List<Document> = emptyList() constructor(
lateinit var content: String
lateinit var published: String
var to: List<String> = emptyList()
var cc: List<String> = emptyList()
var sensitive: Boolean = false
var inReplyTo: String? = null
protected constructor() : super()
@Suppress("LongParameterList")
constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
name: String, override val id: String,
id: String?, var attributedTo: String,
attributedTo: String, var content: String,
content: String, var published: String,
published: String, var to: List<String> = emptyList(),
to: List<String> = emptyList(), var cc: List<String> = emptyList(),
cc: List<String> = emptyList(), var sensitive: Boolean = false,
sensitive: Boolean = false, var inReplyTo: String? = null,
inReplyTo: String? = null, var attachment: List<Document> = emptyList()
attachment: List<Document> = emptyList() ) : Object(
) : super( type = add(type, "Note")
type = add(type, "Note"), ),
name = name, HasId {
id = id
) {
this.attributedTo = attributedTo
this.content = content
this.published = published
this.to = to
this.cc = cc
this.sensitive = sensitive
this.inReplyTo = inReplyTo
this.attachment = attachment
}
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Note) return false if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false if (!super.equals(other)) return false
other as Note
if (id != other.id) return false
if (attributedTo != other.attributedTo) return false if (attributedTo != other.attributedTo) return false
if (attachment != other.attachment) return false
if (content != other.content) return false if (content != other.content) return false
if (published != other.published) return false if (published != other.published) return false
if (to != other.to) return false if (to != other.to) return false
if (cc != other.cc) return false if (cc != other.cc) return false
if (sensitive != other.sensitive) return false if (sensitive != other.sensitive) return false
if (inReplyTo != other.inReplyTo) return false if (inReplyTo != other.inReplyTo) return false
if (attachment != other.attachment) return false
return true return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + (attributedTo?.hashCode() ?: 0) result = 31 * result + id.hashCode()
result = 31 * result + attachment.hashCode() result = 31 * result + attributedTo.hashCode()
result = 31 * result + (content?.hashCode() ?: 0) result = 31 * result + content.hashCode()
result = 31 * result + (published?.hashCode() ?: 0) result = 31 * result + published.hashCode()
result = 31 * result + to.hashCode() result = 31 * result + to.hashCode()
result = 31 * result + cc.hashCode() result = 31 * result + cc.hashCode()
result = 31 * result + sensitive.hashCode() result = 31 * result + sensitive.hashCode()
result = 31 * result + (inReplyTo?.hashCode() ?: 0) result = 31 * result + (inReplyTo?.hashCode() ?: 0)
result = 31 * result + attachment.hashCode()
return result return result
} }
override fun toString(): String { override fun toString(): String =
return "Note(attributedTo=$attributedTo, attachment=$attachment, " + "Note(id='$id', attributedTo='$attributedTo', content='$content', published='$published', to=$to, cc=$cc, sensitive=$sensitive, inReplyTo=$inReplyTo, attachment=$attachment) ${super.toString()}"
"content=$content, published=$published, to=$to, cc=$cc, sensitive=$sensitive," +
" inReplyTo=$inReplyTo) ${super.toString()}"
}
} }

View File

@ -2,47 +2,23 @@ package dev.usbharu.hideout.activitypub.domain.model
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
open class Person : Object { open class Person
var preferredUsername: String? = null @Suppress("LongParameterList")
var summary: String? = null constructor(
var inbox: String? = null
var outbox: String? = null
var url: String? = null
private var icon: Image? = null
var publicKey: Key? = null
var endpoints: Map<String, String> = emptyMap()
var following: String? = null
var followers: String? = null
protected constructor() : super()
@Suppress("LongParameterList")
constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
name: String, override val name: String,
id: String?, override val id: String,
preferredUsername: String?, var preferredUsername: String?,
summary: String?, var summary: String?,
inbox: String?, var inbox: String?,
outbox: String?, var outbox: String?,
url: String?, var url: String?,
icon: Image?, private var icon: Image?,
publicKey: Key?, var publicKey: Key?,
endpoints: Map<String, String> = emptyMap(), var endpoints: Map<String, String> = emptyMap(),
followers: String?, var followers: String?,
following: String? var following: String?
) : super(add(type, "Person"), name, id = id) { ) : Object(add(type, "Person")), HasId, HasName {
this.preferredUsername = preferredUsername
this.summary = summary
this.inbox = inbox
this.outbox = outbox
this.url = url
this.icon = icon
this.publicKey = publicKey
this.endpoints = endpoints
this.followers = followers
this.following = following
}
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true

View File

@ -2,11 +2,24 @@ package dev.usbharu.hideout.activitypub.domain.model
import dev.usbharu.hideout.activitypub.domain.model.objects.Object import dev.usbharu.hideout.activitypub.domain.model.objects.Object
open class Tombstone : Object { open class Tombstone(type: List<String> = emptyList(), override val id: String) :
constructor( Object(add(type, "Tombstone")),
type: List<String> = emptyList(), HasId {
name: String = "Tombstone", override fun equals(other: Any?): Boolean {
actor: String? = null, if (this === other) return true
id: String if (javaClass != other?.javaClass) return false
) : super(add(type, "Tombstone"), name, actor, id) if (!super.equals(other)) return false
other as Tombstone
return id == other.id
}
override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + id.hashCode()
return result
}
override fun toString(): String = "Tombstone(id='$id') ${super.toString()}"
} }

View File

@ -5,41 +5,53 @@ import dev.usbharu.hideout.activitypub.domain.model.objects.Object
import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer import dev.usbharu.hideout.activitypub.domain.model.objects.ObjectDeserializer
import java.time.Instant import java.time.Instant
open class Undo : Object { open class Undo : Object, HasId, HasActor {
@JsonDeserialize(using = ObjectDeserializer::class) @JsonDeserialize(using = ObjectDeserializer::class)
@Suppress("VariableNaming") @Suppress("VariableNaming")
var `object`: Object? = null var `object`: Object? = null
var published: String? = null var published: String? = null
override val actor: String
override val id: String
protected constructor() : super()
constructor( constructor(
type: List<String> = emptyList(), type: List<String> = emptyList(),
name: String,
actor: String, actor: String,
id: String?, id: String,
`object`: Object, `object`: Object,
published: Instant published: Instant
) : super(add(type, "Undo"), name, actor, id) { ) : super(add(type, "Undo")) {
this.`object` = `object` this.`object` = `object`
this.published = published.toString() this.published = published.toString()
this.id = id
this.actor = actor
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Undo) return false if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false if (!super.equals(other)) return false
other as Undo
if (`object` != other.`object`) return false if (`object` != other.`object`) return false
return published == other.published if (published != other.published) return false
if (actor != other.actor) return false
if (id != other.id) return false
return true
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + (`object`?.hashCode() ?: 0) result = 31 * result + (`object`?.hashCode() ?: 0)
result = 31 * result + (published?.hashCode() ?: 0) result = 31 * result + (published?.hashCode() ?: 0)
result = 31 * result + actor.hashCode()
result = 31 * result + id.hashCode()
return result return result
} }
override fun toString(): String = "Undo(`object`=$`object`, published=$published) ${super.toString()}" override fun toString(): String {
return "Undo(`object`=$`object`, published=$published, actor='$actor', id='$id') ${super.toString()}"
}
} }

View File

@ -12,41 +12,29 @@ open class Object : JsonLd {
set(value) { set(value) {
field = value.filter { it.isNotBlank() } field = value.filter { it.isNotBlank() }
} }
var name: String? = null
var actor: String? = null
var id: String? = null
protected constructor() protected constructor()
constructor(type: List<String>, name: String? = null, actor: String? = null, id: String? = null) : super() { constructor(type: List<String>) : super() {
this.type = type.filter { it.isNotBlank() } this.type = type.filter { it.isNotBlank() }
this.name = name
this.actor = actor
this.id = id
} }
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (other !is Object) return false if (javaClass != other?.javaClass) return false
if (!super.equals(other)) return false if (!super.equals(other)) return false
if (type != other.type) return false other as Object
if (name != other.name) return false
if (actor != other.actor) return false
if (id != other.id) return false
return true return type == other.type
} }
override fun hashCode(): Int { override fun hashCode(): Int {
var result = super.hashCode() var result = super.hashCode()
result = 31 * result + type.hashCode() result = 31 * result + type.hashCode()
result = 31 * result + (name?.hashCode() ?: 0)
result = 31 * result + (actor?.hashCode() ?: 0)
result = 31 * result + (id?.hashCode() ?: 0)
return result return result
} }
override fun toString(): String = "Object(type=$type, name=$name, actor=$actor, id=$id) ${super.toString()}" override fun toString(): String = "Object(type=$type) ${super.toString()}"
companion object { companion object {
@JvmStatic @JvmStatic

View File

@ -1,16 +1,15 @@
package dev.usbharu.hideout.activitypub.domain.model.objects package dev.usbharu.hideout.activitypub.domain.model.objects
import com.fasterxml.jackson.annotation.JsonCreator
@Suppress("VariableNaming") @Suppress("VariableNaming")
open class ObjectValue : Object { open class ObjectValue : Object {
var `object`: String? = null lateinit var `object`: String
protected constructor() : super() @JsonCreator
constructor(type: List<String>, name: String?, actor: String?, id: String?, `object`: String?) : super( constructor(type: List<String>) : super(
type, type
name,
actor,
id
) { ) {
this.`object` = `object` this.`object` = `object`
} }