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

com.netflix.serialization.SerializationUtils Maven / Gradle / Ivy

package com.netflix.serialization;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import com.google.common.base.Preconditions;

public class SerializationUtils {

    public static  T deserializeFromString(Deserializer deserializer, String content, TypeDef typeDef) 
            throws IOException {
        Preconditions.checkNotNull(deserializer);
        ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes("UTF-8"));
        return deserializer.deserialize(in, typeDef);
    }
    
    public static  String serializeToString(Serializer serializer, T obj, TypeDef typeDef) 
            throws IOException {
        return new String(serializeToBytes(serializer, obj, typeDef), "UTF-8");
    }
    
    public static  byte[] serializeToBytes(Serializer serializer, T obj, TypeDef typeDef) 
            throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        serializer.serialize(out, obj, typeDef);
        return out.toByteArray();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy