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> boolean
accept(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> T
convertValue(V value)
String
getAcceptedClassList()
Converts theaccepts()
class array to a printable stringString
getArg(int index)
Return the indexed argumentString[]
getArgs()
Returns the arguments passed into the concrete ValueConverter instanceabstract <V> T
getConvertedValue(V value)
perform the value conversion and return the result<V> String
getInvalidMessage(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:ValueConverter
Specifies the list of value types this converter will accept. An empty list indicates this converter will accept ALL types- Specified by:
accepts
in 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:
getArgs
in 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:
convertValue
in 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
-