I think it should be quite easy but I really can't make it work.
I'm returning a Pojo, from a WebMethod:
@WebMethod
public SubCategoria getSubCategorias() throws JAXBException {
SubCategoria a = subCategoriaEJB.getAllSubCategorias().get(1);
return a;
}
I'm just returning the first one, to try.
Im using soapUI to test my Ws.
The response is:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getSubCategoriasResponse xmlns:ns2="http://webService/">
<return>
<categoria>
<descripcion>Categoria Unica</descripcion>
<idCategoria>1</idCategoria>
</categoria>
<descripcion>asd123213</descripcion>
<idSubCategoria>2</idSubCategoria>
</return>
</ns2:getSubCategoriasResponse>
</S:Body>
</S:Envelope>
I want that "return" node to be called "SubCategoria". I can't really make it work with the XmlRootElement Annotation.
Here my Pojo (SubCategoria)
package ejb.Entidades;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.xml.bind.annotation.XmlRootElement;
@Entity
@XmlRootElement(name="SubCategoria")
public class SubCategoria {
@Id
private Integer idSubCategoria;
@ManyToOne
private Categoria categoria;
private String descripcion;
public Integer getIdSubCategoria() {
return idSubCategoria;
}
public void setIdSubCategoria(Integer idSubCategoria) {
this.idSubCategoria = idSubCategoria;
}
public String getDescripcion() {
return descripcion;
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
public Categoria getCategoria() {
return categoria;
}
public void setCategoria(Categoria categoria) {
this.categoria = categoria;
}
}
Someone with a clue?
Thanks in advance.
You should use @WebResult
annotation:
@WebMethod
@WebResult(name = "subCategoria")
public SubCategoria getSubCategorias() throws JAXBException {
SubCategoria a = subCategoriaEJB.getAllSubCategorias().get(1);
return a;
}