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

com.iwbfly.myhttp.lifecycles.param.BodyLifeCycle Maven / Gradle / Ivy

The newest version!
package com.iwbfly.myhttp.lifecycles.param;

import com.iwbfly.myhttp.annotation.Body;
import com.iwbfly.myhttp.lifecycles.ParameterAnnotationLifeCycle;
import com.iwbfly.myhttp.mapping.MappingParameter;
import com.iwbfly.myhttp.mapping.MappingVariable;
import com.iwbfly.myhttp.reflection.MyhttpMethod;
import com.iwbfly.myhttp.utils.StringUtils;

/**
 * @author pangyajun
 * @since 2021/11/27 11:07
 **/
public class BodyLifeCycle implements ParameterAnnotationLifeCycle {

    @Override
    public void onParameterInitialized(MyhttpMethod method, MappingParameter parameter, Body annotation) {
        String name = annotation.value();
        String filterName = annotation.filter();
        if (StringUtils.isNotEmpty(name)) {
            parameter.setName(name);
            MappingVariable variable = new MappingVariable(name, parameter.getType());
            variable.setIndex(parameter.getIndex());
            method.addVariable(name, variable);
            parameter.setObjectProperties(false);
        } else {
            parameter.setObjectProperties(true);
        }
        method.processParameterFilter(parameter, filterName);
        parameter.setTarget(MappingParameter.TARGET_BODY);
        method.addNamedParameter(parameter);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy