Open wajda opened 4 years ago
Thanks for reporting this issue! Serializing and deserializing scala enums is not trivial to implement, here you can find some details: https://github.com/FasterXML/jackson-module-scala/wiki/Enumerations
As a temporary workaround I would suggest you using:
Alternatively, you can use jackson-dataformat-velocypack in combination with jackson-module-scala. It (partially) supports scala enumeration mapping, as documented here: https://github.com/FasterXML/jackson-module-scala/wiki/Enumerations
Eg. something like this:
import com.arangodb.jackson.dataformat.velocypack.VPackMapper
import com.fasterxml.jackson.core.`type`.TypeReference
import com.fasterxml.jackson.module.scala.{DefaultScalaModule, JsonScalaEnumeration}
object Weekday extends Enumeration {
type Weekday = Value
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}
class WeekdayType extends TypeReference[Weekday.type]
case class WeekdayHolder(@JsonScalaEnumeration(classOf[WeekdayType]) weekday: Weekday.Weekday)
object HelloWorld {
def main(args: Array[String]): Unit = {
val obj = WeekdayHolder(Weekday.Fri)
val mapper = new VPackMapper().registerModule(DefaultScalaModule)
val bytes = mapper.writeValueAsBytes(obj)
val decodedBytes: WeekdayHolder = mapper.readValue(bytes, classOf[WeekdayHolder])
assert(decodedBytes.weekday == Weekday.Fri)
}
}
thanks, will take look.
produces