You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Jim Dibble <jd...@amberpoint.com> on 2002/05/25 00:34:10 UTC

Problems with Axis's XML<--> Java Mapping

I'm encountering problems with Axis's XML<--> Java mapping.
 
Does Axis assume that a class with getName and setName methods also has
a field named "name"?  I have an example where my get/set methods
operate on "_name", and it causes problems for Axis.
 
I created a class PurchaseOrder that is sent as a parameter to my
service.  The class looks like this:
 
public class PurchaseOrder
{
    private String _id;
    private String _customerName;
    private String _address;
    private String _city;
    private String _state;
    private java.util.Vector _itemVector;
    OrderItem[] itemArray = new OrderItem[] {};
 
    public PurchaseOrder()
    {
        _itemVector = new Vector();
    }
 
    public String getId()
    {
        return _id;
    }
 
    public void setId(String id)
    {
        _id = id;
    }
 
    public String getCustomerName()
    {
        return _customerName;
    }
 
    public void setCustomerName(String customerName)
    {
        _customerName = customerName;
    }
 
    public String getAddress()
    {
        return _address;
    }
 
    public void setAddress(String address)
    {
        _address = address;
    }
 
    public String getCity()
    {
        return _city;
    }
 
    public void setCity(String city)
    {
        _city = city;
    }
 
    public String getState()
    {
        return _state;
    }
 
    public void setState(String state)
    {
        _state = state;
    }
 
    public OrderItem[] getItems()
    {
        return (OrderItem[])(_itemVector.toArray(itemArray));
    }
 
    public void setItems(OrderItem[] items)
    {
        for (int i=0; i < items.length; i++)
        {
            _itemVector.addElement(items[i]);
        }
    }
 
    protected void addItem(OrderItem item)
    {
        _itemVector.addElement(item);
    }
 
}
 
There's also a similar OrderItem class, with fields beginning with "_".
 
My wsdd file contains beanMapping entries like this:
<beanMapping qname="ord:PurchaseOrder"
languageSpecificType="java:com.amberpoint.tutorial.orders.PurchaseOrder"
/>
<beanMapping qname="ord:OrderItem"
languageSpecificType="java:com.amberpoint.tutorial.orders. OrderItem"/>
 
 
When I generate client code and write a test client, I run into a
problem when I send a message to the web service. The client seems to
generate an XML document with elements beginning with upper-case
characters:
<CustomerName>Cole Hardware</CustomerName>
<City>San Francisco</City>
<State>CA</State>
 
But Axis does not seem to recognize the elements if they start with
upper-case characters.  (I changed them by hand to lower-case
characters, and the problem went away).
My service also has a method that returns a PurchaseOrder as a return
value.  I notice that the response SOAP message for this operation uses
lower-case characters for the element names.  It seems like the
generated client code is capable of handling the lower-case version, but
produces the upper-case version.  The Axis server code can only handle
the lower-case version, and always produces the lower-case version.
Note that the schema in the generated WSDL file contains all elements
starting with an upper-case character.
 
Is this a known bug?  Is there any workaround other than rewriting the
code for my parameter classes so that field names match getter/setter
names?
 
Jim