Hi All, Alen,
sorry but I've yet another question: how (if it's possible) can I
override the default converters with mines? For example, I wrote my
boolean converter that's able to convert boolean values given a set of
boolean string values (i.e. { "true", "yes", "y", "on", "1" }).
When launching the Injector, I get the following error:

1) Multiple converters can convert '0' [...]
Please adjust your type converter configuration to avoid overlapping matches.

Any suggestion will be very appreciated. Best regards!
Simo

On Thu, Jan 7, 2010 at 2:42 PM, Simone Tripodi <[email protected]> wrote:
> Hi Alen,
> I suppose so, because with your suggestion my code is finally working :)
> Best regards, see you!
> Simo
>
> On Thu, Jan 7, 2010 at 12:43 PM, Alen Vrečko <[email protected]> wrote:
>> Hi, Simo.
>>
>> You're welcome. I think you just found a bug in the documentation.
>>
>> convertToTypes(Matchers.only(DateTime.class), new DateTimeConverter
>> ());
>>
>> should be
>>
>> convertToTypes(Matchers.only(TypeLiteral.get(DateTime.class)), new
>> DateTimeConverter());
>>
>> or something similar.
>>
>> Cheers
>> Alen
>>
>> On Jan 6, 10:27 pm, Simone Tripodi <[email protected]> wrote:
>>> Hi Alen,
>>> thank a lot, it is nicely working :)
>>> I got in confusion reading the javadoc 
>>> here:http://google-guice.googlecode.com/svn/trunk/javadoc/com/google/injec...
>>> Thanks once again, your help is more thank appreciated!
>>> All the best,
>>> Simo
>>>
>>>
>>>
>>> On Wed, Jan 6, 2010 at 10:12 PM, Alen Vrečko <[email protected]> wrote:
>>> > Hi,
>>>
>>> > Your Matcher is wrong. You need to match TypeLiteral, but you are
>>> > matching a Class.
>>>
>>> > Change Matchers.only(URL.class) to Matchers.only(TypeLiteral.get
>>> > (URL.class)).
>>>
>>> > Alternatively you could make a utility method url and do something
>>> > like
>>>
>>> > .annotatedWith(named("url")).to(url("http://code.google.com/";));
>>>
>>> > Cheers
>>> > Alen
>>>
>>> > On Jan 6, 7:37 pm, Simone Tripodi <[email protected]> wrote:
>>> >> Hi all guys,
>>> >> I'm just trying to use the Binder#convertToTypes to convert URLs in that 
>>> >> way:
>>>
>>> >> @Override
>>> >>     protected void configure() {
>>> >>         this.binder().convertToTypes(Matchers.only(URL.class), new
>>> >> TypeConverter {
>>>
>>> >>     public Object convert(String value, TypeLiteral<?> toType) {
>>> >>         try {
>>> >>             return new URL(value);
>>> >>         } catch (URISyntaxException e) {
>>> >>             throw new RuntimeException("String vaue '"
>>> >>                     + value
>>> >>                     + "' is not a valid URL", e);
>>> >>         }
>>> >>     }});
>>>
>>> >>     }
>>>
>>> >> then I annotate the POJO field:
>>>
>>> >> class FakeConfig {
>>>
>>> >>     @Inject
>>> >>     @Named("url")
>>> >>     private URL url;
>>>
>>> >>     ....
>>>
>>> >> }
>>>
>>> >> and finally in different module (it comes from a 3rd part developed
>>> >> application):
>>>
>>> >> Injector injector = Guice.createInjector(
>>> >>                 new AbstractModule() {
>>> >>                     @Override
>>> >>                     protected void configure() {
>>> >>                         this.bindConstant()
>>> >>                             .annotatedWith(Names.named("url"))
>>> >>                             .to("http://code.google.com/";);
>>> >>                     }
>>> >>                 });
>>>
>>> >> I get the following error:
>>>
>>> >> com.google.inject.ConfigurationException: Guice configuration errors:
>>>
>>> >> 1) No implementation for java.net.URL annotated with
>>> >> @com.google.inject.name.Named(value=url) was bound.
>>> >>   while locating java.net.URL annotated with
>>> >> @com.google.inject.name.Named(value=url)
>>>
>>> >> Am I misunderstanding or missing something? Thanks in advance, any
>>> >> hint is very appreciated.
>>> >> Best regards,
>>> >> Simo
>>>
>>> >> --http://www.google.com/profiles/simone.tripodi
>>>
>>> > --
>>> > You received this message because you are subscribed to the Google Groups 
>>> > "google-guice" group.
>>> > To post to this group, send email to [email protected].
>>> > To unsubscribe from this group, send email to 
>>> > [email protected].
>>> > For more options, visit this group 
>>> > athttp://groups.google.com/group/google-guice?hl=en.
>>>
>>> --http://www.google.com/profiles/simone.tripodi
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "google-guice" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> For more options, visit this group at 
>> http://groups.google.com/group/google-guice?hl=en.
>>
>>
>>
>>
>
>
>
> --
> http://www.google.com/profiles/simone.tripodi
>



-- 
http://www.google.com/profiles/simone.tripodi
-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.


Reply via email to