org.enodeframework.eventing.impl.DefaultEventSerializer.kt Maven / Gradle / Ivy
package org.enodeframework.eventing.impl
import org.enodeframework.common.serializing.SerializeService
import org.enodeframework.eventing.DomainEventMessage
import org.enodeframework.eventing.EventSerializer
import org.enodeframework.infrastructure.TypeNameProvider
/**
* @author [email protected]
*/
class DefaultEventSerializer(
private val typeNameProvider: TypeNameProvider,
private val serializeService: SerializeService
) : EventSerializer {
override fun serialize(evnts: List): Map {
return evnts.associateBy({ k -> typeNameProvider.getTypeName(k.javaClass) },
{ v -> serializeService.serialize(v) })
}
override fun deserialize(data: Map): List {
return data.map { (key, value) ->
val eventType = typeNameProvider.getType(key)
serializeService.deserialize(value, eventType) as DomainEventMessage
}
}
}