
com.github.jsonparser.util.ValidationUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-parser Show documentation
Show all versions of json-parser Show documentation
The library performs an operation on JSON and returns CSV data in the following output formats: String, File, and Writer.
package com.github.jsonparser.util;
import com.github.jsonparser.exception.JsonParsingException;
import java.util.logging.Logger;
/**
* Useful utilities to validate dependencies
*
* @author Ram Alapure
* @version 1.0
* @since 17/02/2020
*/
public class ValidationUtil {
public static final Logger log = Logger.getLogger(ValidationUtil.class.getName());
private ValidationUtil() {
}
/**
*
* Asserts that the specified parameter value is not null
and if it
* is, throws an JsonParsingException
with the specified error
* message.
*
*
* @param object Object to assert on
* @param fieldName Field name to display in exception message if null
* @throws JsonParsingException
*/
public static void rejectNull(T object, String fieldName) throws JsonParsingException {
if (object == null || (object instanceof String && object.toString().trim().length() == 0)) {
String message = String.format("%s cannot be null or empty.", fieldName);
log.severe(message);
throw new JsonParsingException(message);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy