Ildelian
Ildelian

Reputation: 1318

Pass Java Map<String,Object> to WebService

I have a SOAP Request that have a List of Objects. The Objects hava a java Object field.

When i receive the request in my Java WebService implemented method, the all the values of the object field are a instance of "com.sun.org.apache.xerces.internal.dom.ElementNSImpl" instead of the original object class.

How i can pass a Java Object to a Web Service without lost the original java class of all the values?

The classes:

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;

import javax.xml.bind.annotation.XmlTransient;

public class Request implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1358291145144128010L;

    private List<externalField> externalFields;

    public Request(){}

    public void setExternalFields(List<externalField> camposFFCCExternal) {
        this.camposFFCCExternal = camposFFCCExternal;
    }

    public List<externalField> getExternalFields() {
        return camposFFCCExternal;
    }
}

The externalField class:

import java.io.Serializable;

public class externalField implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 8248866248138301848L;
    private String key;
    private Object value;

    public void setClave(String key) {
        this.key = key;
    }
    public String getClave() {
        return key;
    }
    public void setValor(Object value) {
        this.value = value;
    }
    public Object getValor() {
        return value;
    }

}

Upvotes: 2

Views: 1120

Answers (1)

Sorontur
Sorontur

Reputation: 510

I think you cannot do this without telling jaxb what types are possible. You can do this with anyType if you have influence to the xml serialisation: How to create java object from 'anyType' returned from service using JAXB?

Or if the set of possible Objects is known you can try to define a choice of types:

http://blog.bdoughan.com/2010/10/jaxb-and-xsd-choice-xmlelements.html

Hope this gives you some idea to move on.

Upvotes: 1

Related Questions