Done ticket
This commit is contained in:
@@ -37,4 +37,24 @@ public class FieldValidator {
|
||||
throw new ValidationException(Status.VALIDATION_ERROR, errors);
|
||||
}
|
||||
}
|
||||
public FieldValidator minLength(String value, Long minLength, String fieldName) {
|
||||
if (minLength != null && value != null && value.length() < minLength) {
|
||||
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_FIELD_MIN_LENGTH), fieldName, minLength));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public FieldValidator maxLength(String value, Long maxLength, String fieldName) {
|
||||
if (maxLength != null && value != null && value.length() > maxLength) {
|
||||
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_FIELD_MAX_LENGTH), fieldName, maxLength));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public FieldValidator matchesPattern(String value, String pattern, String fieldName) {
|
||||
if (value != null && pattern != null && !value.matches(pattern)) {
|
||||
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.VALIDATION_FIELD_PATTERN), fieldName));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user