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

me.smecsia.gawain.jackson.JacksonStateSerializer.groovy Maven / Gradle / Ivy

Go to download

Microframework focusing on data processing and aggregation in distributed environment

There is a newer version: 0.1.9
Show newest version
package me.smecsia.gawain.jackson

import com.fasterxml.jackson.databind.ObjectMapper
import groovy.transform.CompileStatic
import me.smecsia.gawain.serialize.ToJsonStateSerializer

import static me.smecsia.gawain.util.StringUtil.isEmpty
/**
 * @author Ilya Sadykov
 */
@CompileStatic
class JacksonStateSerializer implements ToJsonStateSerializer {
    private final ObjectMapper objectMapper

    JacksonStateSerializer(GawainObjectMapperProvider provider = new GawainObjectMapperProvider()) {
        this.objectMapper = provider.provide()
    }

    @Override
    String serialize(Map notSerializedObject) {
        objectMapper.writeValueAsString(notSerializedObject)
    }

    @Override
    Map deserialize(String serializedObject) {
        isEmpty(serializedObject) ?  null : objectMapper.readValue(serializedObject, Map)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy