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

org.ssf4j.jackson.JacksonDeserializer Maven / Gradle / Ivy

There is a newer version: 0.4
Show newest version
package org.ssf4j.jackson;

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

import org.ssf4j.Deserializer;

import com.fasterxml.jackson.databind.ObjectMapper;

public class JacksonDeserializer implements Deserializer {

	protected JacksonSerialization serde;
	protected InputStream in;
	protected Class type;
	protected ObjectMapper mapper;
	
	public JacksonDeserializer(JacksonSerialization serde, InputStream in, ObjectMapper mapper, Class type) {
		this.serde = serde;
		this.in = in;
		this.type = type;
		this.mapper = mapper != null ? mapper : new ObjectMapper();
	}
	
	@Override
	public void close() throws IOException {
		in.close();
	}

	@Override
	public T read() throws IOException {
		serde.getLock().lock();
		try {
			return mapper.readValue(in, type);
		} finally {
			serde.getLock().unlock();
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy