How to generate empty String values, " " using wsdlOptions for artifacts in CXF ?

Solution Verified - Updated -

Issue

  • We are migration IBM Web integrations to Fuse integrations.
    In the IBM Web product it is possible in a Web Service response to add empty mandatory xml elements if they are not set, eg:
<beskrivning></beskrivning>
  • In Fuse we are using wsdl2java maven plugin to generate the Java code. Se the plugin example in attached pom file.
    Code generated with the plugin wsdl2java typically looks like this;
    This xsd definition:
<xsd:element minOccurs="1" name="beskrivning" type="xsd:string" ></xsd:element>

Generates this java code:

@XmlElement(required = true)
    protected String beskrivning;

  public String getBeskrivning() {
        return beskrivning;
    }

    public void setBeskrivning(String value) {
        this.beskrivning = value;
    }

Is it possible to use a wsdlOption or plugin for fields that are mandatory and of type String to generate getters that returns a default value of "".

Like this:

 public String getBeskrivning() {
         if(beskrivning == null){
              return "";
        }
        return beskrivning;
    }

Is there a way to accomplish this with wsdl2java?
We know that the best solution would be to fix the schemas to have minOccurs="0", but that is not possible right know.

Environment

  • Red Hat JBoss Fuse
    • 6.x
  • Apache CXF

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content