Done ticket

This commit is contained in:
rajesh
2024-09-12 15:33:09 +05:30
parent 02bb5877b6
commit 492317be2e
26 changed files with 913 additions and 8 deletions

View File

@@ -5,12 +5,14 @@ import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.micrometer.common.util.StringUtils;
import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
@@ -99,7 +101,13 @@ public class Utils {
}
public static <T> List<T> convertJsonStringToList(String jsonString, Class<T> clazz) {
try {
return mapper.readValue(jsonString, new TypeReference<List<T>>() {});
TypeReference<List<T>> typeRef = new TypeReference<List<T>>() {
@Override
public Type getType() {
return TypeFactory.defaultInstance().constructCollectionType(List.class, clazz);
}
};
return mapper.readValue(jsonString, typeRef);
} catch (Exception e) {
e.printStackTrace();
// Handle the exception appropriately (e.g., throw a custom exception)
@@ -129,5 +137,14 @@ public class Utils {
}
return null;
}
public static <T, U> U convertSourceObjectToDestinationObject(T source, Class<U> destinationClass) {
try {
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.registerModule(new JavaTimeModule());
return mapper.convertValue(source, destinationClass);
} catch (Exception e) {
log.error("Error converting object: " + e.getMessage(), e);
}
return null;
}
}