Hi
 
I find where it happens in:
package org.apache.axis.encoding;

in  public class SerializationContext
when  public void serialize(QName elemQName,
                          Attributes attributes,
                          Object value,
                          QName xmlType,
                          Boolean sendNull,
                          Boolean sendType)
        throws IOException
    {
        serialize(elemQName, attributes, value, xmlType, null, sendNull, sendType);//here is problem
       
    } is called ,

The function serialize calls :
void serializeActual(QName elemQName,
                                Attributes attributes,
                                Object value,
                                QName xmlType,
                                Class javaClass,
                                Boolean sendType)
 
javaClass is always null so when getActualJavaClass  look at the code of :
 
 priva te Class getActualJavaClass(QName xmlType, Class javaType, Object obj) {
        Class cls = obj.getClass();
       
        if ((xmlType != null
                    && Constants.isSchemaXSD(xmlType.getNamespaceURI()) && "anyType".equals(xmlType.getLocalPart()))
                || (javaType != null
                        && (javaType.isArray() || javaType == Object.class))) {
            return cls;
        }
       
        if (javaType != null && cls != javaType && !cls.isArray()) {
            return javaType;
        }
       
        return cls;
    }
 
it always return cls so i join my solution with it,you need to add in  the function serializeActual some codes :
 
 private void serializeActual(QName elemQName,
                                Attributes attributes,
                                Object value,
                                QName xmlType,
                                Class javaClass,
                                Boolean sendType)
        throws IOException
    {
        boolean shouldSend Type = (sendType == null) ? shouldSendXSIType() :
            sendType.booleanValue();
        if (value != null) {
            TypeMapping tm = getTypeMapping();
            if (tm == null) {
                throw new IOException(
                        Messages.getMessage("noSerializer00",
                                             value.getClass().getName(),
                                             "" + this));
            }
            // Set currentXMLType to the one desired one.
            // Note for maxOccurs usage this xmlType is the
            // type of the component not the type of the array.
            currentXMLType = xmlType;
            // if we're looking for xsd:anyType, accept anything...
            if (Constants.equals(Constants.XSD_ANYTYPE,xmlType)){
                xmlType = null;
                shouldSendType = true;
            }
            // Try getting a serializer for the prefered xmlType
            QNameHolder actualXMLType = new QNameHolder();
 
             ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////          
            //here is my fix for bugs if not javaClass was always null
           javaClass=value.getClass();
           Class javaType = getActualJavaClass(xmlType, javaClass, value);
          ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
                   
           
           Serializer ser = getSerializer(javaType, xmlType,
                                           actualXMLType);
            if ( ser != null ) {
                // Send the xmlType if indicated or if
                // the actual xmlType is different than the
                // prefered xmlType
                if (shouldSendType ||
                    (xmlType != null &&
                     (!xmlType.equals(actualXMLType.value)))) {
                    if(!isEncoded()) {
                        if (Constants.isSOAP_ENC(actualXMLType.value.getNamespaceURI())) {
                            // Don't write SOAP_ENC types (i.e. Array) if we're not using encoding
                        } else if (javaType.isPrimitive() && javaClass != null && JavaUtils.getWrapperClass(javaType) == javaClass) {
                            // Don't write xsi:type when serializing primitive wrapper value as primitive type.
                        }
                        else {
                            if(!(javaType.isArray() && xmlType != null && Constants.isSchemaXSD(xmlType.getNamespaceURI())) ) {
                                writeXMLType = actualXMLType.value;
                            }
                        }
                    } else {
                        writeXMLType = actualXMLType.value;
                    }
                }
                // -----------------
                // NOTE: I have seen doc/lit tests that use
                // the type name as the element name in multi-ref cases
                // (for example <soapenc:Array ... >)
                // In such cases the xsi:type is not passed along.
                // -----------------
                // The multiref QName is our own fake name.
                // It may be beneficial to set the name to the
                // type name, but I didn't see any improvements
                // in the interop tests.
                //if (name.equals(multirefQName) && type != null)
                //    name = type;
                ser.serialize(elemQName, attributes, value, this);
                return;
            }
            throw new IOException(Messages.getMessage("noSerializer00",
                    value.getClass().getName(), "" + tm));
        }
        // !!! Write out a generic null, or get type info from somewhere else?
    }
Anyone to test it?

"Dies Koper (JIRA)" <[email protected]> a écrit :
[ http://issues.apache.org/jira/browse/AXIS-2280?page=comments#action_12363513 ]

Dies Koper commented on AXIS-2280:
----------------------------------

I have reproduced this problem in my environment and would like to note something that I think is rather important to this issue.

Base class: Data (field: String name)
Subclass: MoreData (field: int size)
method parameter: Data[]

client test 1 (OK):
creates Data array with "new Data{xx}" passing Data instance
SOAP message shows data field; impl receives data instance

client test 2 (NG<- point of this Bug):
creates Data array with "new Data{xx}" passing MoreData instance
SOAP message shows data field, no size field; impl receives Data instance

client test 3 ((almost)OK<- I added as missing link):
creates MoreData array with "new MoreData{xx}" passing MoreData instance
SOAP message shows data and size fie lds; impl receives MoreData instance
BUT: the array containing the MoreData instance is of type Data[], not MoreData[], so returning this to the client gives the same problem as in test 2 again.

=> I assume Axis serializer checks instance of the array, not of its elements, and assumes all elements would be of the same type. Also, should the deserializer create the array (not just the elements) using the same type as the elements, not the base type?

[workaround?]
See client test 3: use the same (sub)type for the array reference as the elements you want to transmit.
#What if you have elements of different subclasses of the base class? Hmm..


[Relevant parts of SOAP requests]
test 1:

data


test 2:

moreData


test3:

moreData
11




> Array elements of derived (XSD extension type) are not serialized correctly
> ---------------------------------------------------------------------------
>
> Key: AXIS-2280
> URL: http://issues.apache.org/jira/browse/AXIS-2280
> Project: Apache Axis
> Type: Bug
> Components: Serialization/Deserialization
> Versions: 1.3
> Reporter: Peter Canning
> Priority: Blocker
> Attachments: arrayExtensionTest.wsdl, arrayExtensionTestClient.java, src_with_more_stdout.zip
>
> This is a regression from Axis (Java) 1.2.1.
> If an operation take a parameter whose type is an array (maxOccurs="unbounded") of a base type, and the client passes an array containing a value whose type is derived (an XSD extension) from the base type, the value is serialized as the base type, and the additional elements in the derived type are omitted. In addtion the eleme nt for the value is missing the expected xsi:type attribute.
> I will attach an example to demonstate the problem.

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira



Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international. Téléchargez la version beta.

Reply via email to