This method converts the given
objectToConvert
value into an instance of this parameter's {@link #getType() type}. If the object to convert is not already of the parameter's type, a constructor is called to build one. It will be assumed that this parameter's type class has a constructor that takes a single argument of the same type as
objectToConvert
. If this constructor does exist, it is used to create the new instance by passing
objectToConvert
to it. The resulting object is returned (this object will be of the parameter's defined type. The original
objectToConvert
will be returned as-is (i.e. no conversion will be performed) if either of the following is true:
objectToConvert
is null
objectToConvert
is already an instance of this parameter's type
Note that if
objectToConvert
is
null
, but this parameter definition {@link #isNullable() does not allow for null}, an exception is thrown.
This method is useful when needing to convert text-based command line parameters to their actual Java type representations.
@param objectToConvert the object to convert to the given type
@return the converted object
@throws InvalidParameterValueException if the given object is
null
but this parameter definitiondoes not allow for
null
, or the parameter's type specifies a primitive type, or the conversion failed due to a problem occurring while instantiating the new typed object