org.ssf4j.jackson.JacksonSerializer Maven / Gradle / Ivy
package org.ssf4j.jackson;
import java.io.IOException;
import java.io.OutputStream;
import org.ssf4j.Serializer;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JacksonSerializer implements Serializer {
protected OutputStream out;
protected ObjectMapper mapper;
public JacksonSerializer(OutputStream out, ObjectMapper mapper) throws IOException {
this.out = out;
this.mapper = mapper != null ? mapper : new ObjectMapper();
}
@Override
public void flush() throws IOException {
out.flush();
}
@Override
public void close() throws IOException {
flush();
out.close();
}
@Override
public void write(T object) throws IOException {
mapper.writeValue(out, object);
}
}