org.onetwo.common.jackson.JsonDataBinder Maven / Gradle / Ivy
The newest version!
package org.onetwo.common.jackson;
import java.io.File;
import org.onetwo.common.date.DateUtils;
import org.onetwo.common.file.FileUtils;
public class JsonDataBinder {
protected JsonMapper jsonMapper = JsonMapper.defaultMapper().setDateFormat(DateUtils.DATE_TIME);
protected Class dataType;
protected String dataFilePath;
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;
File file = new File(path);
T data = jsonMapper.fromJson(file, dataType);;
return data;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy