atos1990 / orika

Automatically exported from code.google.com/p/orika
0 stars 0 forks source link

Convenient way of declaring types as immutable #42

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In the case of mapping immutable types, it should be safe to return the source.

Therefore, it'd be nice to have a shorthand way of doing this.

Initially, I tried the following:

public class ImmutableConverter<S> extends CustomConverter<S> {
    @Override
    public D convert(S source, Type<? extends D> destinationType) {
        return (D) source;
    }
}

However, this fails because the constructor for CustomConverter requires two 
generic parameters.

Therefore, I have to create subclasses for each immutable type.

Ie., I'd like:

factory.getConverterFactory().registerConverter(new 
ImmutableConverter<DateTime>());

Instead, I currently have the following:

factory.getConverterFactory().registerConverter(new DateTimeCopier());
class DateTimeCopier extends ImmutableConverter<DateTime,DateTime> {};

Not terrible by any means, but could be a little more elegant.

Thanks

Original issue reported on code.google.com by martyp...@mango-factory.com on 22 Aug 2012 at 10:51

GoogleCodeExporter commented 9 years ago
Please take a look at PassThroughConverter, 

exemple of use,

factory.getConverterFactory().registerConverter(new PassThroughConverter(<as 
many as types you want, varargs>));

I hope this can help you.

Original comment by elaat...@gmail.com on 22 Aug 2012 at 11:02

GoogleCodeExporter commented 9 years ago

Original comment by elaat...@gmail.com on 24 Aug 2012 at 10:14