jTransfo 0.11 released, CDI support

jTransfo 0.11 is now available. This new version adds a jtransfo-cdi module.

The object finders, type converters and convert interceptors which are found in the CDI registry are automatically registered. When you want to configure beans which need to be added in the registry, you can do this using a producer.

public class StringEnumTypeConverterProducer {
 
    @Produces
    public StringEnumTypeConverter<Gender> getGenderTypeConverter() {
        return new StringEnumTypeConverter<Gender>(Gender.class);
    }
 
}

To allow you to configure the order of the convert interceptors, you can annotate your interceptors with InterceptorOrder.

@InterceptorOrder(1) // should be a lower order than SetExtraConvertInterceptor to assure it being applied "after"
public class AppendExtraConvertInterceptor implements ConvertInterceptor {
 
    @Override
    public <T> T convert(Object source, T target, boolean isTargetTo, ConvertSourceTarget next, String... tags) {
        T res = next.convert(source, target, isTargetTo, tags);
        if (target instanceof PersonDomain) {
            PersonDomain person = (PersonDomain) res;
            person.setExtra(person.getExtra() + " sleep.");
        }
        return res;
    }
 
}

The examples can be seen in action as part of the jTransfo test suite.

Posted in Release