How to convert a method of passed arguments to a single object in Java

There is a Jax-Ws web service method that takes 20 arguments. the arguments must be checked, so I have to pass them all to another validator method separately or create an object of the class, passing the arguments to the constructor, and then use this object to call the validation method

Here is an example

WebService Interface Object

public interface IEcommWs {
    @WebMethod
    @RequestWrapper(localName = "payment", className = "ge.jibo.ecomm.ws.wrapper.PaymentRequest")
    @ResponseWrapper(localName = "paymentResponse", className = "ge.jibo.ecomm.ws.wrapper.PaymentResponse")
    public void payment(@WebParam(name = "requestType", mode = Mode.IN) RequestType requestType,
            @WebParam(name = "merchantId", mode = Mode.IN) String merchantId,
            .... another 20 param ....
            @WebParam(name = "response", mode = Mode.OUT) Holder<Response> response,
            @WebParam(name = "paymentResult", mode = Mode.OUT) Holder<PaymentResult> paymentResult);
}

and implementation

@WebService(endpointInterface = "ge.jibo.ecomm.ws.IEcommWs")
public class EcommWs implements IEcommWs {

    @Override
    public void payment(RequestType requestType, String merchantId, 
            .... another 20 param ....
            Holder<Response> response,
            Holder<PaymentResult> paymentResult) {

        Validator.validateInput(RequestType requestType, String merchantId, .... another 20 param ....);

        or 
        PaymentRequest requestParams = new PaymentRequest(RequestType requestType, String merchantId, .... another 20 param ....);

        Validator.validateInput(requestParams);
    }

Is it possible to convert all these arguments into a single object without using the class constructor?

like this

PaymentRequest requestParams = getPaymentMethodParams();
+4
source share

Source: https://habr.com/ru/post/1694851/


All Articles