Merge branch 'develop' into feature/JDK11
Some checks failed
IntegryManagementSystem_Multi/pipeline/head There was a failure building this commit
Some checks failed
IntegryManagementSystem_Multi/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -74,6 +74,7 @@ public class CsvMapper<T> {
|
||||
public List<T> deserialize(String csv, Class<T> dtoClass, String splitChar) throws Exception {
|
||||
List<T> outputList = null;
|
||||
String[] headers = null;
|
||||
Integer rows = 0;
|
||||
|
||||
String delimiter = UtilityString.identifyLineDelimiter(csv);
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(csv.getBytes());
|
||||
@@ -83,6 +84,7 @@ public class CsvMapper<T> {
|
||||
for (int i = 0; i < byteBuffer.capacity(); i++) {
|
||||
line.append((char) byteBuffer.get());
|
||||
if (line.toString().endsWith(delimiter)) {
|
||||
rows++;
|
||||
if (firstLine) {
|
||||
firstLine = false;
|
||||
headers = line.toString().replace(delimiter, "").split(splitChar);
|
||||
@@ -105,37 +107,44 @@ public class CsvMapper<T> {
|
||||
line = new StringBuilder();
|
||||
continue;
|
||||
}
|
||||
String[] datas = line.toString().replace(delimiter, "").split(splitChar);
|
||||
T bean = (T) dtoClass.newInstance();
|
||||
for (int j = 0; j < datas.length; j++) {
|
||||
String header = headers[j].trim();
|
||||
if (header.compareTo("") != 0) {
|
||||
Field field = map.get(header.toLowerCase());
|
||||
|
||||
if (field != null) {
|
||||
try {
|
||||
String[] datas = line.toString().replace(delimiter, "").split(splitChar);
|
||||
T bean = (T) dtoClass.newInstance();
|
||||
for (int j = 0; j < datas.length; j++) {
|
||||
String header = headers[j].trim();
|
||||
if (header.compareTo("") != 0) {
|
||||
Field field = map.get(header.toLowerCase());
|
||||
|
||||
DtoField dtoField = field.getAnnotation(DtoField.class);
|
||||
if (field != null) {
|
||||
|
||||
field.setAccessible(true);
|
||||
DtoField dtoField = field.getAnnotation(DtoField.class);
|
||||
|
||||
field.setAccessible(true);
|
||||
|
||||
Object columnValue;
|
||||
if (field.getGenericType() != String.class && UtilityString.isNullOrEmpty(datas[j].trim())) {
|
||||
columnValue = null;
|
||||
} else {
|
||||
columnValue = datas[j].trim();
|
||||
}
|
||||
|
||||
Object o = SqlFieldHolder.applyConvert(columnValue, field.getGenericType());
|
||||
field.set(bean, o);
|
||||
|
||||
Object columnValue;
|
||||
if (field.getGenericType() != String.class && UtilityString.isNullOrEmpty(datas[j].trim())) {
|
||||
columnValue = null;
|
||||
} else {
|
||||
columnValue = datas[j].trim();
|
||||
}
|
||||
|
||||
Object o = SqlFieldHolder.applyConvert(columnValue, field.getGenericType());
|
||||
field.set(bean, o);
|
||||
|
||||
}
|
||||
}
|
||||
line = new StringBuilder();
|
||||
if (outputList == null) {
|
||||
outputList = new ArrayList<T>();
|
||||
}
|
||||
outputList.add(bean);
|
||||
|
||||
} catch(Exception e) {
|
||||
throw new Exception("ERRORE DI SINTASSI SU RIGA " + rows);
|
||||
}
|
||||
line = new StringBuilder();
|
||||
if (outputList == null) {
|
||||
outputList = new ArrayList<T>();
|
||||
}
|
||||
outputList.add(bean);
|
||||
|
||||
}
|
||||
}
|
||||
byteBuffer.clear();
|
||||
|
||||
Reference in New Issue
Block a user