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

de.tsl2.nano.replication.serializer.SerializeJSON Maven / Gradle / Ivy

There is a newer version: 2.5.1
Show newest version
package de.tsl2.nano.replication.serializer;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import com.fasterxml.jackson.databind.ObjectMapper;


public class SerializeJSON implements Serializer {
    public static final String KEY = "JSON";
    @Override
    public String getKey() {
        return KEY;
    }
    @Override
    public String getExtension() {
        return "json";
    }
    @Override
    public ByteArrayOutputStream serialize(Object obj) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            new ObjectMapper().writer().writeValue(out, obj);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
        return out;
    }
    @Override
    public  T deserialize(InputStream stream, Class type) {
        try {
			return new ObjectMapper().readerFor(type).readValue(stream);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy