feature/creation #2
|
|
@ -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