Done ticket GEPAFINBE-3

This commit is contained in:
harish
2024-08-14 15:31:00 +05:30
parent 2773dfa034
commit e09f61f918
51 changed files with 2107 additions and 70 deletions

View File

@@ -0,0 +1,49 @@
package net.gepafin.tendermanagement.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.stream.Collectors;
public class Utils {
public static final Logger log = LoggerFactory.getLogger(Utils.class);
private static final ObjectMapper mapper = new ObjectMapper()
.registerModule(new JavaTimeModule())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
public static <T, U> U convertObject(T source, Class<U> destinationClass) {
try {
return mapper.convertValue(source, destinationClass);
} catch (Exception e) {
log.error("Error converting object: " + e.getMessage(), e);
}
return null;
}
public static <T, U> List<U> convertSourceListToDestinationList(List<T> sourceList, Class<U> destinationClass) {
try {
return sourceList.stream()
.map(source -> mapper.convertValue(source, destinationClass))
.collect(Collectors.toList());
} catch (Exception e) {
log.error("Error converting list: " + e.getMessage(), e);
}
return null;
}
public static <T, U> List<U> convertSourceToList(T source, Class<U> destinationClass) {
try {
// Convert single source object to a single-element list of destination type
return List.of(mapper.convertValue(source, destinationClass));
} catch (Exception e) {
log.error("Error converting single object to list: " + e.getMessage(), e);
}
return null;
}
}