org.onetwo.common.spring.utils.ClassPathJsonDataBinder Maven / Gradle / Ivy
package org.onetwo.common.spring.utils;
import java.io.IOException;
import org.onetwo.common.jackson.JsonDataBinder;
import org.springframework.core.io.ClassPathResource;
/**
* @author wayshall
*
*/
public class ClassPathJsonDataBinder extends JsonDataBinder {
public static E from(Class dataType, String dataFilePath){
ClassPathJsonDataBinder binder = new ClassPathJsonDataBinder<>(dataType, dataFilePath);
return binder.buildData();
}
public ClassPathJsonDataBinder(Class dataType, String dataFilePath) {
super(dataType, dataFilePath);
}
public T buildData(){
ClassPathResource res = new ClassPathResource(dataFilePath);
T data;
try {
data = jsonMapper.fromJson(res.getInputStream(), dataType);
} catch (IOException e) {
throw new RuntimeException("build data error:"+e.getMessage(), e);
}
return data;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy