You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Luis M. Villa" <kh...@yahoo.com.INVALID> on 2017/11/28 13:58:53 UTC

Trouble with @XmlElement and duplicated attributes

Hello all,
I'm starting to develop web services using Apache CXF and Spring 4. I've created a hello world service as such:

@WebService
public interface HelloWorldService {

    HelloWorldResponseSOAP hello(HelloWorldRequestSOAP request);

}
@WebService(endpointInterface = "my.first.service.HelloWorldService")
public class HelloWorldServiceImpl implements HelloWorldService {

    public HelloWorldResponseSOAP hello(HelloWorldRequestSOAP request) {
        final HelloWorldResponseSOAP helloWorldResponseSOAP = new HelloWorldResponseSOAP();
        helloWorldResponseSOAP.setGreeting("Hello " + request.getName() + ", " + request.getDate());
        return helloWorldResponseSOAP;
    }

}

public class HelloWorldResponseSOAP {

    private String greeting;

    public String getGreeting() {
        return this.greeting;
    }

    public void setGreeting(String greeting) {
        this.greeting = greeting;
    }

}

import java.util.Date;

import javax.xml.bind.annotation.XmlElement;

public class HelloWorldRequestSOAP {

    @XmlElement(nillable = true)
    private Date date;
    private String name;

    public Date getDate() {
        return this.date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

My problem is that, when I don't annotate 'date' attribute with XmlElement and an empty date is sent using a client (such as soapUI), I get an Unmarshalling error (when I specify a correct date all goes well). But when the annotation is present, the server does not start, throwing this error:
La clase tiene dos propiedades con el mismo nombre "date"  <-- translated: The class has two properties with the same name "date"
    this problem is related to the following location:
        at public java.util.Date es.xunta.amtega.cenpos.integracion.HelloWorldRequestSOAP.getDate()
        at es.xunta.amtega.cenpos.integracion.HelloWorldRequestSOAP
        at private es.xunta.amtega.cenpos.integracion.HelloWorldRequestSOAP es.xunta.amtega.cenpos.integracion.jaxws_asm.Hello.arg0
        at es.xunta.amtega.cenpos.integracion.jaxws_asm.Hello
    this problem is related to the following location:
        at private java.util.Date es.xunta.amtega.cenpos.integracion.HelloWorldRequestSOAP.date
        at es.xunta.amtega.cenpos.integracion.HelloWorldRequestSOAP
        at private es.xunta.amtega.cenpos.integracion.HelloWorldRequestSOAP es.xunta.amtega.cenpos.integracion.jaxws_asm.Hello.arg0
        at es.xunta.amtega.cenpos.integracion.jaxws_asm.Hello
Anyone knows what I'm doing wrong?
Thank you all in advance