예제 #1
0
 /**
  * Registers converters mapping them to their corresponding parameterized type.
  *
  * @param converter
  * @return a reference to this builder.
  */
 public GensonBuilder withConverters(Converter<?>... converter) {
   for (Converter<?> c : converter) {
     Type typeOfConverter =
         TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Converter.class, c.getClass()));
     typeOfConverter = TypeUtil.expandType(typeOfConverter, c.getClass());
     registerConverter(c, typeOfConverter);
   }
   return this;
 }
예제 #2
0
 private <T> void registerConverter(Converter<T> converter, Type type) {
   if (serializersMap.containsKey(type))
     throw new IllegalStateException(
         "Can not register converter "
             + converter.getClass()
             + ". A custom serializer is already registered for type "
             + type);
   if (deserializersMap.containsKey(type))
     throw new IllegalStateException(
         "Can not register converter "
             + converter.getClass()
             + ". A custom deserializer is already registered for type "
             + type);
   serializersMap.put(type, converter);
   deserializersMap.put(type, converter);
 }