Class DefaultTypeConverter

java.lang.Object
com.globalmentor.model.DefaultTypeConverter
All Implemented Interfaces:
TypeConverter

public class DefaultTypeConverter extends Object implements TypeConverter
A default implementation of a type converter.

The following types can be converted to the listed types:

Boolean
boolean
Character
char
Number
Long, long, Integer, int, Double, double, Float, float
String
char[], Enum, Pattern, URIPath
Author:
Garret Wilson
  • Field Details

    • INSTANCE

      public static final DefaultTypeConverter INSTANCE
      The default, shared instance of the converter.
  • Constructor Details

    • DefaultTypeConverter

      protected DefaultTypeConverter()
      Default constructor; used only for the singleton instance and for extension.
  • Method Details

    • convert

      public <T> T convert(Object object, Class<T> requiredType) throws IllegalArgumentException
      Description copied from interface: TypeConverter
      Converts an object from one type to another. If the object is already of the correct type, no action occurs.
      Specified by:
      convert in interface TypeConverter
      Type Parameters:
      T - The type of object required.
      Parameters:
      object - The object to convert.
      requiredType - The class representing required type of the object.
      Returns:
      The object as the required type, or null if the object cannot be converted to the required type.
      Throws:
      IllegalArgumentException - if the given object should be able to be converted to the required type but something about its state, format, or contents prevented the conversion.