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

io.vertx.up.uca.rs.argument.ContextFiller Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
package io.vertx.up.uca.rs.argument;

import io.vertx.ext.web.RoutingContext;
import io.vertx.up.uca.rs.Filler;
import io.vertx.up.fn.Fn;
import io.vertx.up.runtime.ZeroSerializer;

import java.util.Map;

public class ContextFiller implements Filler {
    @Override
    public Object apply(final String name,
                        final Class paramType,
                        final RoutingContext context) {
        final Map data = context.data();
        final Object value = data.get(name);
        return Fn.getNull(() -> {
            if (paramType == value.getClass()) {
                return value;
            } else {
                final String valueStr = value.toString();
                return ZeroSerializer.getValue(paramType, valueStr);
            }
        }, value);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy