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

org.vertexium.serializer.xstream.XStreamVertexiumSerializer Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium.serializer.xstream;

import com.thoughtworks.xstream.XStream;
import org.vertexium.VertexiumSerializer;

public class XStreamVertexiumSerializer implements VertexiumSerializer {
    private static final XStream xstream;
    private static final byte[] EMPTY = new byte[0];

    static {
        xstream = new XStream();
        xstream.ignoreUnknownElements();
    }

    @Override
    public byte[] objectToBytes(final Object object) {
        if (object == null) {
            return EMPTY;
        }
        synchronized (object) {
            return xstream.toXML(object).getBytes();
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public  T bytesToObject(byte[] bytes) {
        if (bytes == null || bytes.length == 0) {
            return null;
        }
        return (T) xstream.fromXML(new String(bytes));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy