test #369
@@ -1,7 +1,6 @@
|
||||
package kr.co.vividnext.sodalive.content.series.translation
|
||||
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import kr.co.vividnext.sodalive.common.BaseEntity
|
||||
import javax.persistence.AttributeConverter
|
||||
import javax.persistence.Column
|
||||
@@ -22,7 +21,7 @@ class SeriesTranslation(
|
||||
data class SeriesTranslationPayload(
|
||||
val title: String,
|
||||
val introduction: String,
|
||||
val keywords: String
|
||||
val keywords: List<String>
|
||||
)
|
||||
|
||||
@Converter(autoApply = false)
|
||||
@@ -38,10 +37,34 @@ class SeriesTranslationPayloadConverter : AttributeConverter<SeriesTranslationPa
|
||||
return SeriesTranslationPayload(
|
||||
title = "",
|
||||
introduction = "",
|
||||
keywords = ""
|
||||
keywords = emptyList()
|
||||
)
|
||||
}
|
||||
// 호환 처리: 과거 스키마에서 keywords가 String 이었을 수 있으므로 유연하게 파싱한다.
|
||||
return try {
|
||||
val node = objectMapper.readTree(dbData)
|
||||
val title = node.get("title")?.asText() ?: ""
|
||||
val introduction = node.get("introduction")?.asText() ?: ""
|
||||
val keywordsNode = node.get("keywords")
|
||||
val keywords: List<String> = when {
|
||||
keywordsNode == null || keywordsNode.isNull -> emptyList()
|
||||
keywordsNode.isArray -> keywordsNode.mapNotNull { it.asText(null) }.filter { it.isNotBlank() }
|
||||
keywordsNode.isTextual -> listOfNotNull(keywordsNode.asText()).filter { it.isNotBlank() }
|
||||
else -> emptyList()
|
||||
}
|
||||
SeriesTranslationPayload(
|
||||
title = title,
|
||||
introduction = introduction,
|
||||
keywords = keywords
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
// 파싱 실패 시 안전한 기본값 반환
|
||||
SeriesTranslationPayload(
|
||||
title = "",
|
||||
introduction = "",
|
||||
keywords = emptyList()
|
||||
)
|
||||
}
|
||||
return objectMapper.readValue(dbData)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
Reference in New Issue
Block a user