public final class Convert extends Object
This class provides less type-safety than the general jOOQ API methods. For
instance, it accepts arbitrary Converter objects in methods like
convert(Collection, Converter) and convert(Object, Class),
trying to retrofit the Object argument to the type provided in
Converter.fromType() before performing the actual conversion.
| Modifier and Type | Field and Description |
|---|---|
static Set<String> |
FALSE_VALUES
All string values that can be transformed into a boolean
false value. |
static Set<String> |
TRUE_VALUES
All string values that can be transformed into a boolean
true value. |
| Modifier and Type | Method and Description |
|---|---|
static <T> List<T> |
convert(Collection<?> collection,
Class<? extends T> type)
Convert a collection of objects to a list of
T, using
convert(Object, Class) |
static <U> List<U> |
convert(Collection<?> collection,
Converter<?,? extends U> converter)
Convert a collection of objects to a list of
T, using
convert(Object, Converter) |
static Object[] |
convert(Object[] values,
Class<?>[] types)
Convert an array of values to a matching data type
This converts
values[i] to types[i] |
static Object[] |
convert(Object[] values,
Field<?>[] fields)
Convert an array of values to a matching data type
This converts
values[i] to fields[i].getType() |
static <T> T |
convert(Object from,
Class<? extends T> toClass)
Convert an object to a type.
|
static <U> U |
convert(Object from,
Converter<?,? extends U> converter)
Convert an object to a type.
|
static Object[] |
convertArray(Object[] from,
Class<?> toClass)
Convert an array into another one by these rules
If
toClass is not an array class, then make it an array
class first
If toClass is an array class, then create an instance
from it, and convert all elements in the from array one by
one, using convert(Object, Class)
|
static <U> U[] |
convertArray(Object[] from,
Converter<?,? extends U> converter)
Convert an array into another one using a converter
This uses
convertArray(Object[], Class) to convert the array to
an array of Converter.fromType() first, before converting that
array again to Converter.toType() |
static <U> U[] |
convertCollection(Collection from,
Class<? extends U[]> to) |
public static final Set<String> TRUE_VALUES
true value.public static final Object[] convert(Object[] values, Field<?>[] fields)
This converts values[i] to fields[i].getType()
public static final Object[] convert(Object[] values, Class<?>[] types)
This converts values[i] to types[i]
public static final <U> U[] convertArray(Object[] from, Converter<?,? extends U> converter) throws DataTypeException
This uses convertArray(Object[], Class) to convert the array to
an array of Converter.fromType() first, before converting that
array again to Converter.toType()
from - The array to convertconverter - The data type converterDataTypeException - - When the conversion is not possiblepublic static final Object[] convertArray(Object[] from, Class<?> toClass) throws DataTypeException
toClass is not an array class, then make it an array
class firsttoClass is an array class, then create an instance
from it, and convert all elements in the from array one by
one, using convert(Object, Class)from - The array to converttoClass - The target array typeDataTypeException - - When the conversion is not possiblepublic static final <U> U[] convertCollection(Collection from, Class<? extends U[]> to)
public static final <U> U convert(Object from, Converter<?,? extends U> converter) throws DataTypeException
from - The source objectconverter - The data type converterDataTypeException - - When the conversion is not possiblepublic static final <T> T convert(Object from, Class<? extends T> toClass) throws DataTypeException
null is always converted to null,
regardless of the target type.StringObjectNumber types can be converted to other
Number typesNumber or String types can be converted
to Boolean. Possible (case-insensitive) values for
true:
11.0yyestrueonenabled
Possible (case-insensitive) values for false:
00.0nnofalseoffdisabled
All other values evaluate to null
Date subtypes (Date, Time,
Timestamp), as well as most Temporal subtypes (
LocalDate, LocalTime, LocalDateTime,
OffsetTime, OffsetDateTime, as well as Instant)
can be converted into each other.String types can be converted into URI,
URL and Filenull is converted into the initialisation value (e.g.
0 for int, false for
boolean)byte[] can be converted into String, using
the platform's default charsetObject[] can be converted into any other array type, if
array elements can be converted, tooDataTypeExceptionfrom - The object to converttoClass - The target typeDataTypeException - - When the conversion is not possiblepublic static final <T> List<T> convert(Collection<?> collection, Class<? extends T> type) throws DataTypeException
T, using
convert(Object, Class)collection - The list of objectstype - The target typeDataTypeException - - When the conversion is not possibleconvert(Object, Class)public static final <U> List<U> convert(Collection<?> collection, Converter<?,? extends U> converter) throws DataTypeException
T, using
convert(Object, Converter)collection - The collection of objectsconverter - The data type converterDataTypeException - - When the conversion is not possibleconvert(Object, Converter)Copyright © 2019. All rights reserved.