me.smecsia.gawain.jackson.JacksonStateSerializer.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gawain-jackson Show documentation
Show all versions of gawain-jackson Show documentation
Microframework focusing on data processing and aggregation in distributed environment
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