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

io.github.itroadlabs.apicross.beanvalidation.springmvc.params.ParamNameDataBinder Maven / Gradle / Ivy

The newest version!
package io.github.itroadlabs.apicross.beanvalidation.springmvc.params;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.web.servlet.mvc.method.annotation.ExtendedServletRequestDataBinder;

import java.util.Map;

public class ParamNameDataBinder extends ExtendedServletRequestDataBinder {
    private final Map renameMapping;

    public ParamNameDataBinder(Object target, String objectName, Map renameMapping) {
        super(target, objectName);
        this.renameMapping = renameMapping;
    }

    @Override
    protected void addBindValues(MutablePropertyValues mpvs, jakarta.servlet.ServletRequest request) {
        super.addBindValues(mpvs, request);
        for (Map.Entry entry : renameMapping.entrySet()) {
            String parameterName = entry.getKey();
            String propertyName = entry.getValue();
            if (mpvs.contains(parameterName)) {
                mpvs.add(propertyName, mpvs.getPropertyValue(parameterName).getValue());
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy