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 Details

    • AbstractJSONValueConverter

      public AbstractJSONValueConverter​(String... args)
      Constructor
      Parameters:
      args - vararg array of argument strings
  • Method Details

    • accepts

      public abstract Class<?>[] 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 interface ValueConverter<T>
      Returns:
      a list of class types
    • getAcceptedClassList

      public String getAcceptedClassList()
      Converts the accepts() class array to a printable string
      Returns:
    • getInvalidMessage

      public <V> String getInvalidMessage​(V value)
      Return a formatted invalid type message
      Type Parameters:
      V - the value type
      Parameters:
      value - the value
      Returns:
      the formatted invalid message
    • getArgs

      public String[] getArgs()
      Returns the arguments passed into the concrete ValueConverter instance
      Specified by:
      getArgs in interface ValueConverter<T>
    • getArg

      public String getArg​(int index)
      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

      public <V> T convertValue​(V value) throws JSONConversionException
      Specified by:
      convertValue in interface ValueConverter<T>
      Throws:
      JSONConversionException
    • getConvertedValue

      public abstract <V> T getConvertedValue​(V value) throws JSONConversionException
      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