Updated form field response bean
This commit is contained in:
@@ -1,19 +1,25 @@
|
||||
package net.gepafin.tendermanagement.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
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.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.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static final Logger log = LoggerFactory.getLogger(Utils.class);
|
||||
@@ -82,5 +88,46 @@ public class Utils {
|
||||
setter.accept(newValue);
|
||||
}
|
||||
}
|
||||
public static <T> String convertListToJsonString(List<T> list) {
|
||||
try {
|
||||
return mapper.writeValueAsString(list);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
// Handle exception or throw a custom exception
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static <T> List<T> convertJsonStringToList(String jsonString, Class<T> clazz) {
|
||||
try {
|
||||
return mapper.readValue(jsonString, new TypeReference<List<T>>() {});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// Handle the exception appropriately (e.g., throw a custom exception)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static String convertMapIntoJsonString(Map<String, Object> map) {
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
if (MapUtils.isNotEmpty(map)) {
|
||||
return mapper.writeValueAsString(map);
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static Map<String, Object> convertIntoJson(String jsonString) {
|
||||
if (jsonString != null && !jsonString.isEmpty()) {
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true);
|
||||
return mapper.readValue(jsonString, Map.class);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user