mirror of https://github.com/usbharu/Hideout.git
fix: カスタムシリアライザーを修正
This commit is contained in:
parent
94d7564336
commit
b1d341c944
|
@ -20,6 +20,10 @@ application {
|
||||||
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
|
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.withType<Test> {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
@ -54,6 +58,7 @@ dependencies {
|
||||||
implementation("io.ktor:ktor-client-core:$ktor_version")
|
implementation("io.ktor:ktor-client-core:$ktor_version")
|
||||||
implementation("io.ktor:ktor-client-cio:$ktor_version")
|
implementation("io.ktor:ktor-client-cio:$ktor_version")
|
||||||
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
|
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
|
||||||
|
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
|
||||||
}
|
}
|
||||||
|
|
||||||
jib {
|
jib {
|
||||||
|
|
|
@ -13,4 +13,6 @@ open class Follow : Object{
|
||||||
this.`object` = `object`
|
this.`object` = `object`
|
||||||
this.actor = actor
|
this.actor = actor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,13 @@ import com.fasterxml.jackson.annotation.JsonCreator
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.fasterxml.jackson.core.TreeNode
|
import com.fasterxml.jackson.core.TreeNode
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer
|
import com.fasterxml.jackson.databind.JsonDeserializer
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
|
||||||
|
|
||||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
||||||
open class JsonLd {
|
open class JsonLd {
|
||||||
@JsonProperty("@context")
|
@JsonProperty("@context")
|
||||||
@JsonDeserialize(using = ContextDeserializer::class)
|
@JsonDeserialize(contentUsing = ContextDeserializer::class)
|
||||||
var context:List<String> = emptyList()
|
var context:List<String> = emptyList()
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
|
@ -21,8 +22,12 @@ open class JsonLd {
|
||||||
protected constructor()
|
protected constructor()
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ContextDeserializer : JsonDeserializer<List<String>>() {
|
public class ContextDeserializer : JsonDeserializer<String>() {
|
||||||
override fun deserialize(p0: com.fasterxml.jackson.core.JsonParser?, p1: com.fasterxml.jackson.databind.DeserializationContext?): List<String> {
|
override fun deserialize(p0: com.fasterxml.jackson.core.JsonParser?, p1: com.fasterxml.jackson.databind.DeserializationContext?): String {
|
||||||
return emptyList()
|
val readTree : JsonNode = p0?.codec?.readTree(p0) ?: return ""
|
||||||
|
if (readTree.isObject) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return readTree.asText()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package dev.usbharu.hideout.ap
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||||
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
|
import org.junit.jupiter.api.Assertions.*
|
||||||
|
|
||||||
|
class ContextDeserializerTest {
|
||||||
|
|
||||||
|
@org.junit.jupiter.api.Test
|
||||||
|
fun deserialize() {
|
||||||
|
//language=JSON
|
||||||
|
val s = """
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"quoteUrl": "as:quoteUrl",
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"Emoji": "toot:Emoji",
|
||||||
|
"featured": "toot:featured",
|
||||||
|
"discoverable": "toot:discoverable",
|
||||||
|
"schema": "http://schema.org#",
|
||||||
|
"PropertyValue": "schema:PropertyValue",
|
||||||
|
"value": "schema:value",
|
||||||
|
"misskey": "https://misskey-hub.net/ns#",
|
||||||
|
"_misskey_content": "misskey:_misskey_content",
|
||||||
|
"_misskey_quote": "misskey:_misskey_quote",
|
||||||
|
"_misskey_reaction": "misskey:_misskey_reaction",
|
||||||
|
"_misskey_votes": "misskey:_misskey_votes",
|
||||||
|
"_misskey_talk": "misskey:_misskey_talk",
|
||||||
|
"isCat": "misskey:isCat",
|
||||||
|
"vcard": "http://www.w3.org/2006/vcard/ns#"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "https://test-misskey-v12.usbharu.dev/follows/9bg1zu54y7/9cydqvpjcn",
|
||||||
|
"type": "Follow",
|
||||||
|
"actor": "https://test-misskey-v12.usbharu.dev/users/9bg1zu54y7",
|
||||||
|
"object": "https://test-hideout.usbharu.dev/users/test3"
|
||||||
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
val readValue = jacksonObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false).readValue<Follow>(s)
|
||||||
|
println(readValue)
|
||||||
|
println(readValue.actor)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue