Using ValueEncoders with Resteasy

The power of Tapestry’s ValueEncoder can be used with RestEasy by implementing

import org.apache.tapestry5.ValueEncoder;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

public class ValueEncodersProvider implements ParamConverterProvider {

    private final ValueEncoderSource valueEncoderSource;

    public ValueEncodersProvider(ValueEncoderSource valueEncoderSource) {
        this.valueEncoderSource = valueEncoderSource;

    public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
        final ValueEncoder<T> encoder = valueEncoderSource.getValueEncoder(rawType);
        if (encoder == null) {
            return null;

        return new ParamConverter<T>() {
            public T fromString(String value) {
                return encoder.toValue(value);

            public String toString(T value) {
                return encoder.toClient(value);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: