All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mastfrog.webapi.builtin.ParameterFromClassNameAndToStringCamelCase Maven / Gradle / Ivy

There is a newer version: 2.9.7
Show newest version
package com.mastfrog.webapi.builtin;

import com.mastfrog.netty.http.client.HttpRequestBuilder;
import com.mastfrog.webapi.Decorator;
import com.mastfrog.webapi.WebCall;

/**
 * Sets a parameter with the class name to the value of toString() on the value.
 * So if you have, say a DisplayName object in scope and its toString() value is
 * "Joe Blow", you get a parameter
 * ?displayname=Joe%20Blow
 *
 * @author Tim Boudreau
 */
public final class ParameterFromClassNameAndToStringCamelCase implements Decorator {

    @Override
    public void decorate(WebCall call, HttpRequestBuilder builder, T obj, Class type) {
        StringBuilder key = new StringBuilder(type.getSimpleName());
        key.setCharAt(0, Character.toLowerCase(key.charAt(0)));
        String val = obj.toString();
        builder.addQueryPair(key.toString(), val);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy