package org.gcube.accounting.datamodel.validations.validators; import java.io.Serializable; import org.gcube.accounting.exception.InvalidValueException; public class ValidLongValidator implements FieldValidator { private static final String ERROR = String.format("Not Instance of %s", Integer.class.getSimpleName()); @Override public Serializable validate(Serializable toValidate) throws InvalidValueException { if(toValidate instanceof Long){ return toValidate; } try { Long longObj = Long.getLong((String) toValidate); if(longObj!=null){ return longObj; } }catch (Exception e) { throw new InvalidValueException(ERROR, e.getCause()); } throw new InvalidValueException(ERROR); } }