Conversion Package
The org.apache.juneau.commons.conversion package provides a lightweight, pluggable type-conversion engine for converting objects between types without requiring a full marshalling context or session.
Core API
Converter
The primary interface for converting objects between types. Use BasicConverter.INSTANCE for a ready-made singleton that handles a wide range of common conversions.
Converter converter = BasicConverter.INSTANCE;
Integer i = converter.to("123", Integer.class);
BasicConverter
A concrete CachingConverter supporting common type conversions (numbers, booleans, dates, collections, arrays, and more) without a MarshallingContext. Exposes the shared BasicConverter.INSTANCE singleton.
long[] a = BasicConverter.INSTANCE.to("1,2,3", long[].class);
CachingConverter
An abstract Converter that lazily discovers conversion functions on first use for a given input/output type pair and caches them for subsequent calls.
ConfigurableConverter
A BasicConverter subclass that accepts one or more ConversionFinder strategies, consulted in order before the built-in conversions.
Extension Points
Conversion
A functional interface representing a single type conversion. The args parameter carries any type arguments needed for parameterized output types.
ConversionFinder
A pluggable strategy for discovering Conversion functions between type pairs; passed to the ConfigurableConverter constructor.
ConverterSession
Provides contextual objects to Conversion functions at call time.
Exceptions
InvalidConversionException
Unchecked exception thrown by Converter.to(Object, Class) when no conversion path exists between two types. Callers unsure whether a conversion is possible can test first rather than catch.