users@jersey.java.net

[Jersey] Re: Improved parameter handling suggestion

From: Adam Walczak <me_at_adamwalczak.info>
Date: Mon, 6 Dec 2010 22:31:40 +0100

Is the any way in Jersey to make it treat empty strings in parameter
injection as null's ?

I tried something hacky like:

@Provider
public class StringStringReaderProvider
    implements StringReaderProvider<String> {

    @Override
    public StringReader<String> getStringReader(
        Class<?> type, Type genericType, Annotation[] annotations) {
        return new StringReader<String>() {

            @Override
            public String fromString(String value) {
                if(value == null) {
                    return null;
                } else if(value.isEmpty()) {
                    return null;
                } else {
                    return value;
                }
            }
        };
    }

}

but it didn't work :o)

-- 
Adam Walczak
www.adamwalczak.info
+48 604 188 992