CXF - How to declare a required attribute and not primitive?

I have a web sercice method that gets an object. One attribute is the "interval", which is an integer.

I would like to make this attribute necessary, but without providing a default value - I want the user to explicitly set the value.

If I use int interval- the attribute is displayed as int, and if the user does not explicitly set the attribute, zero will be sent (Java default for primitive int).

If I use Integer interval- the attribute is displayed as Integer and is declared optional in the WSDL, so the user cannot see that it is needed before sending the request.

If I use Integer intervalwith @XmlElement(required = true)or @XmlElement(nillable = false)- the attribute is displayed as int.

An attribute can have any integer - negative, zero, and positive, so I cannot use the default value to indicate that the attribute is not explicitly set.

I can use BigInteger intervalwith @XmlElement(required = true), but we miss the benefits of using the main type Integer.

I would like to show the attribute as Integer, so I will get null if the user has not set the attribute, and at the same time I would like the WSDL to detect that the attribute is required, so that users know what is required just by looking at the WSDL.

+5
source share
1 answer

@XmlElement(required = true) WSDL , , org.apache.cxf.tools.wsdlto.WSDLToJava WSDL int interval Integer interval.

, "-b" wsdl2java jaxb, xsd: int java.lang.Integer:

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           jaxb:version="2.0">
  <jaxb:globalBindings>
    <jaxb:javaType name="java.lang.Integer"
                   xmlType="xsd:int" />
  </jaxb:globalBindings>
</jaxb:bindings>

@XmlElement(required = true) "-b", (minOccurs = "1" ) Integer Java.

: http://cxf.547215.n5.nabble.com/How-to-declare-an-attribute-required-and-non-primitive-td4815370.html

+3

All Articles