/** * Adds an type converter for the given class * * @param clazz The class you want to register a TypeConverter for * @param converterForClass The converter for this class * @return The Builder itself */ public <T> Builder addTypeConverter(Type clazz, TypeConverter<T> converterForClass) { config.typeConverters.add(clazz, converterForClass); return this; }
/** * Query a {@link TypeConverter} for a given class * * @param clazz The class you want a type converter for * @param <T> The type of the TypeConverter * @return The TypeConverter or throws an Exception * @throws TypeConverterNotFoundException Thrown if no TypeConverter has been found for the given * class */ public <T> TypeConverter<T> getTypeConverter(Class<T> clazz) throws TypeConverterNotFoundException { return typeConverters.get(clazz); }
@Test public void addAndGetTypeConverter() throws IOException { TypeConverters converters = new TypeConverters(); exception.expect(IOException.class); converters.get(TestConverter.class); TestConverter converter = new TestConverter(); converters.add(Object.class, converter); Assert.assertSame(converter, converters.get(Object.class)); exception.expect(IOException.class); converters.get(Date.class); } }