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

com.godmonth.util.jackson.JacksonObjectFactory Maven / Gradle / Ivy

package com.godmonth.util.jackson;

import org.apache.commons.lang3.exception.ContextedRuntimeException;
import org.springframework.core.io.Resource;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author shenyue
 */
public class JacksonObjectFactory {
	private Resource resource;
	private ObjectMapper objectMapper;
	private Class objectType;

	public void setObjectMapper(ObjectMapper objectMapper) {
		this.objectMapper = objectMapper;
	}

	public void setObjectType(Class objectType) {
		this.objectType = objectType;
	}

	public T createObject() {
		try {
			return objectMapper.readValue(resource.getInputStream(), objectType);
		} catch (Exception e) {
			throw new ContextedRuntimeException(e);
		}
	}

	public void setResource(Resource resource) {
		this.resource = resource;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy