Over a million developers have joined DZone.

Using ValueEncoders with Resteasy

DZone's Guide to

Using ValueEncoders with Resteasy

· Java Zone ·
Free Resource

Learn how to stop testing everything every sprint and only test the code you’ve changed. Brought to you by Parasoft.

The power of Tapestry’s ValueEncoder can be used with RestEasy by implementing javax.ws.rs.ext.ParamConverterProvider

import org.apache.tapestry5.ValueEncoder;
import org.apache.tapestry5.services.ValueEncoderSource;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;
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);

Get the top tips for Java developers and best practices to overcome common challenges. Brought to you by Parasoft.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}