SeriesTranslationPayload 키워드 리스트 변환 및 수정
- `SeriesTranslationPayload.keywords` 타입을 `String`에서 `List<String>`으로 변경했습니다. - `SeriesTranslationPayloadConverter`의 `convertToEntityAttribute`를 하위 호환 가능하도록 수정했습니다. - DB에 저장된 JSON에서 `keywords`가 과거 스키마(String)인 경우와 신규 스키마(List)를 모두 안전하게 파싱합니다. - 파싱 실패 또는 공백 입력 시 기본값을 사용합니다(`keywords = []`). - `convertToDatabaseColumn`은 변경 없이 `ObjectMapper`로 직렬화하여 `keywords`가 배열로 저장됩니다.
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package kr.co.vividnext.sodalive.content.series.translation
|
package kr.co.vividnext.sodalive.content.series.translation
|
||||||
|
|
||||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
|
||||||
import kr.co.vividnext.sodalive.common.BaseEntity
|
import kr.co.vividnext.sodalive.common.BaseEntity
|
||||||
import javax.persistence.AttributeConverter
|
import javax.persistence.AttributeConverter
|
||||||
import javax.persistence.Column
|
import javax.persistence.Column
|
||||||
@@ -22,7 +21,7 @@ class SeriesTranslation(
|
|||||||
data class SeriesTranslationPayload(
|
data class SeriesTranslationPayload(
|
||||||
val title: String,
|
val title: String,
|
||||||
val introduction: String,
|
val introduction: String,
|
||||||
val keywords: String
|
val keywords: List<String>
|
||||||
)
|
)
|
||||||
|
|
||||||
@Converter(autoApply = false)
|
@Converter(autoApply = false)
|
||||||
@@ -38,10 +37,34 @@ class SeriesTranslationPayloadConverter : AttributeConverter<SeriesTranslationPa
|
|||||||
return SeriesTranslationPayload(
|
return SeriesTranslationPayload(
|
||||||
title = "",
|
title = "",
|
||||||
introduction = "",
|
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 {
|
companion object {
|
||||||
|
|||||||
Reference in New Issue
Block a user