Class AbstractJSONValueConverter<T>
java.lang.Object
org.ghotibeaun.json.converters.valueconverter.AbstractJSONValueConverter<T>
- Type Parameters:
T-
- All Implemented Interfaces:
ValueConverter<T>
- Direct Known Subclasses:
NumberFormatJSONValueConverter,StringJSONValueConverter
public abstract class AbstractJSONValueConverter<T> extends Object implements ValueConverter<T>
Abstract implementation for the
ValueConverter interface.
Contains utility methods to validate the incoming value type before converting the value- Author:
- Jim Earley (xml.jim@gmail.com)
-
Constructor Summary
Constructors Constructor Description AbstractJSONValueConverter(String... args)Constructor -
Method Summary
Modifier and Type Method Description <V> booleanaccept(V value)Evaluates the value type against the ValueConverter's accepted value typesabstract Class<?>[]accepts()Specifies the list of value types this converter will accept.<V> TconvertValue(V value)StringgetAcceptedClassList()Converts theaccepts()class array to a printable stringStringgetArg(int index)Return the indexed argumentString[]getArgs()Returns the arguments passed into the concrete ValueConverter instanceabstract <V> TgetConvertedValue(V value)perform the value conversion and return the result<V> StringgetInvalidMessage(V value)Return a formatted invalid type message
-
Constructor Details
-
AbstractJSONValueConverter
Constructor- Parameters:
args- vararg array of argument strings
-
-
Method Details
-
accepts
Description copied from interface:ValueConverterSpecifies the list of value types this converter will accept. An empty list indicates this converter will accept ALL types- Specified by:
acceptsin interfaceValueConverter<T>- Returns:
- a list of class types
-
getAcceptedClassList
Converts theaccepts()class array to a printable string- Returns:
-
getInvalidMessage
Return a formatted invalid type message- Type Parameters:
V- the value type- Parameters:
value- the value- Returns:
- the formatted invalid message
-
getArgs
Returns the arguments passed into the concrete ValueConverter instance- Specified by:
getArgsin interfaceValueConverter<T>
-
getArg
Return the indexed argument- Parameters:
index- the index position- Returns:
- the value at the specified index
- Throws:
ArrayIndexOutOfBoundsException- if the index value does not exist
-
accept
public <V> boolean accept(V value)Evaluates the value type against the ValueConverter's accepted value types- Type Parameters:
V- the value type- Parameters:
value- the value- Returns:
- true if the value type matches one of types in the
accepts()array; false otherwise
-
convertValue
- Specified by:
convertValuein interfaceValueConverter<T>- Throws:
JSONConversionException
-
getConvertedValue
perform the value conversion and return the result- Type Parameters:
V- the value type- Parameters:
value- the value- Returns:
- the converted value
- Throws:
JSONConversionException- thrown if a conversion error occurs
-