All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy