public GensonBuilder withDeserializers(Deserializer<?>... deserializer) { for (Deserializer<?> d : deserializer) { Type typeOfConverter = TypeUtil.typeOf(0, TypeUtil.lookupGenericType(Deserializer.class, d.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, d.getClass()); registerDeserializer(d, typeOfConverter); } return this; }
private void addDefaultDeserializers(List<? extends Deserializer<?>> deserializers) { if (deserializers != null) { for (Deserializer<?> deserializer : deserializers) { Type typeOfConverter = TypeUtil.typeOf( 0, TypeUtil.lookupGenericType(Deserializer.class, deserializer.getClass())); typeOfConverter = TypeUtil.expandType(typeOfConverter, deserializer.getClass()); if (!deserializersMap.containsKey(typeOfConverter)) deserializersMap.put(typeOfConverter, deserializer); } } }
private <T> void registerDeserializer(Deserializer<T> deserializer, Type type) { if (deserializersMap.containsKey(type)) throw new IllegalStateException( "Can not register deserializer " + deserializer.getClass() + ". A custom deserializer is already registered for type " + type); deserializersMap.put(type, deserializer); }