コード例 #1
0
ファイル: GensonBuilder.java プロジェクト: 1205469665/genson
 /**
  * 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
ファイル: GensonBuilder.java プロジェクト: 1205469665/genson
 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);
 }