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

org.onetwo.common.jackson.JsonDataBinder Maven / Gradle / Ivy

There is a newer version: 5.2.7
Show newest version
package org.onetwo.common.jackson;

import org.onetwo.common.date.DateUtil;
import org.onetwo.common.file.FileUtils;

public class JsonDataBinder {
	private Class dataType;
	private String dataFilePath;

	private JsonMapper jsonMapper =  JsonMapper.defaultMapper().setDateFormat(DateUtil.DATE_TIME);
	
	public JsonDataBinder(Class dataType) {
		String path = dataType.getName().replace('.', '/')+".data.json";
		this.dataType = dataType;
		this.dataFilePath = path;
	}
	
	public JsonDataBinder(Class dataType, String dataFilePath) {
		super();
		this.dataType = dataType;
		this.dataFilePath = dataFilePath;
	}
	
	public T buildData(){
		String path = FileUtils.getResourcePath("")+dataFilePath;
		T data = jsonMapper.fromJson(path, dataType);;
		return data;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy