Add Converter
This commit is contained in:
parent
8e3f94527d
commit
6ee21f0e87
|
|
@ -0,0 +1,19 @@
|
|||
package org.octopus.internal.db.converters
|
||||
|
||||
import jakarta.persistence.AttributeConverter
|
||||
import jakarta.persistence.Converter
|
||||
import java.time.Month
|
||||
|
||||
@Converter
|
||||
class MonthListConverter : AttributeConverter<List<Month>, String> {
|
||||
|
||||
override fun convertToDatabaseColumn(attribute: List<Month>?): String? {
|
||||
return attribute?.joinToString(separator = ",") { it.name }
|
||||
}
|
||||
|
||||
override fun convertToEntityAttribute(dbData: String?): List<Month>? {
|
||||
return dbData?.split(",")
|
||||
?.filter { it.isNotBlank() }
|
||||
?.mapNotNull { runCatching { Month.valueOf(it.trim()) }.getOrNull() }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue