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

org.atmosphere.gwt20.jackson.JacksonSerializer Maven / Gradle / Ivy

There is a newer version: 2.6.5
Show newest version
package org.atmosphere.gwt20.jackson;

import java.io.IOException;
import java.util.Map;
import org.atmosphere.gwt20.server.SerializationException;
import org.atmosphere.gwt20.server.ServerSerializer;

/**
 *
 * @author p.havelaar
 */
public class JacksonSerializer implements ServerSerializer {

    final JacksonSerializerProvider provider;

    public JacksonSerializer(JacksonSerializerProvider provider) {
        this.provider = provider;
    }
    

    @Override
    public String serialize(Object data) throws SerializationException {
        try {
            return provider.mapper.writeValueAsString(data);
        } catch (IOException ex) {
            throw new SerializationException("Failed to serialize data", ex);
        }
    }
    
    @Override
    public Object deserialize(String data) throws SerializationException{
        try {
            // TODO not the most neat implementation
            return provider.mapper.readValue(data, Map.class);
        } catch (IOException ex) {
            throw new SerializationException("Failed to deserialize data", ex);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy