1

How can I make a parameter required for a soap webservice?

@WebService
public class MyService {
    //how can I make city param required?
    @WebMethod
    public ComplexResponse lookup(@WebParam(name = "city") String city) {

    }
}
membersound
  • 74,158
  • 163
  • 522
  • 986

1 Answers1

4

Adding

@XmlElement(required=true, nillable=false)

to the param should work:

public ComplexResponse lookup(@WebParam(name = "city") @XmlElement(required=true, nillable=false) String city) 
Juned Ahsan
  • 66,028
  • 11
  • 91
  • 129
  • great, I was not aware one can use `@XmlElement` within the method signature. – membersound Jul 23 '14 at 08:43
  • Note that it requires JAX-B 2.2+. See https://stackoverflow.com/questions/8211420/xmlelement-annotation-dissallowed-with-webparam – Pino May 25 '18 at 13:37