org.ssf4j.jackson.JacksonSerialization Maven / Gradle / Ivy
package org.ssf4j.jackson;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.locks.ReentrantLock;
import org.ssf4j.Locked;
import org.ssf4j.Serialization;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Serialization facade that uses Jackson's JSON mapper.
*
* Jackson cannot serialize everything, but comes pretty close.
* @author robin
*
*/
public class JacksonSerialization implements Serialization, Locked {
protected ObjectMapper mapper;
public JacksonSerialization() {}
public JacksonSerialization(ObjectMapper mapper) {
this.mapper = mapper;
}
/**
* {@inheritDoc}
*/
@Override
public JacksonSerializer newSerializer(OutputStream out, Class type)
throws IOException {
return new JacksonSerializer(this, out, mapper);
}
/**
* {@inheritDoc}
*/
@Override
public JacksonDeserializer newDeserializer(InputStream in, Class type)
throws IOException {
return new JacksonDeserializer(this, in, mapper, type);
}
@Override
public boolean isThreadSafe() {
return false;
}
/**
* The lock for this serialization
*/
protected ReentrantLock lock = new ReentrantLock();
@Override
public ReentrantLock getLock() {
return lock;
}
}