[ 
https://issues.apache.org/jira/browse/AXIS2-3797?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12752012#action_12752012
 ] 

Amila Chinthaka Suriarachchi commented on AXIS2-3797:
-----------------------------------------------------

First of all if you take the root cause of this problem, you try to solve it in 
the wrong place.

public class ArrayOfanyType {

    private Object[] anyType;

    public Object[] getAnyType() {
        if (anyType == null) {
            anyType = new Object[0];
        }
        return this.anyType;
    }

    public void setAnyType(Object[] anyType) { 
     this.anyType = anyType;
    }
} 

At runtime what type of objects this.anyTpye Array can have? I don't think it 
is OMElement. it is some type of java objects. eg. String, Integer or any other 
class.

So isn't is correct to generate those classes at the stub rather than an 
OMElement. So the correct solution is to POJO should check the type an 
serialise it properly. Then a question comes what happens for user defined 
classes (eg. Student, Vehicle) 
For those things I think there must be a way to specify them services.xml and 
should show in the wsdl in a separate complex type. Then any client generating 
code for that can create a data binding class for that and maps using the given 
xsi:type in the response.

if some one has a method signature like this,
public void setAnyType(OMElement[] anyType) { 
     this.anyType = anyType;
    }

then generated wsdl should have xs:any to represent this and Stub client 
generates accordingly.

IMHO correct place to fix this issue is at POJO level.

Taking your suggestion to add OMElement support as well to xsd:anyType 
Can you please first check how this done in jaxbri. (i.e -d jaxbri )  
I mean what this the type it generates for xs:anyType element and what happens 
when getting a response with the xsi:type and without it.



> "Unknown type can not serialize" Exception
> ------------------------------------------
>
>                 Key: AXIS2-3797
>                 URL: https://issues.apache.org/jira/browse/AXIS2-3797
>             Project: Axis 2.0 (Axis2)
>          Issue Type: Bug
>          Components: adb
>    Affects Versions: 1.4
>         Environment: Axis2 1.4, Tomcat 5.5.26
>            Reporter: Detelin Yordanov
>         Attachments: full stacktrace.txt, TypeTest.aar, TypeTestClient.java
>
>
> I have a simple POJO service with the following method:
> package org.tempuri.test;
> import org.tempuri.test.data.arrays.ArrayOfanyType;
>  
> public class TypeTest {
>     public ArrayOfanyType retArrayAnyType1D(ArrayOfanyType inArrayAnyType1D) {
>         return inArrayAnyType1D;
>     }
> }
> The ArrayOfanyType is declared like this:
> public class ArrayOfanyType {
>     private Object[] anyType;
>     public Object[] getAnyType() {
>         if (anyType == null) {
>             anyType = new Object[0];
>         }
>         return this.anyType;
>     }
>     public void setAnyType(Object[] anyType) {
>       this.anyType = anyType;
>     }
> }
> I deploy this POJO on an Axis2 1.4 runtime running on Tomcat.
> Then I generate a client stub using the following command:
> wsdl2java -ap -o ./generated -s -u -uw -uri 
> http://localhost:8080/axis2-1.4/services/TypeTest?wsdl
> I use the stub to invoke the service passing an OMElement in the Object array:
> OMFactory factory = OMAbstractFactory.getOMFactory();
> OMNamespace ns = 
> factory.createOMNamespace("http://www.serverside.com/articles/introducingAxiom";,
>  "article");
> OMElement articleElement = factory.createOMElement("Article", ns);
> ArrayOfanyType input = new ArrayOfanyType();
> input.setAnyType(new OMElement[]{articleElement});
> stub.retArrayAnyType1D(input);
> While serializing the ArrayOfanyType ADBBean I get an "Unknown type can not 
> serialize" exception:
> Caused by: javax.xml.stream.XMLStreamException: Unknow type can not serialize
>       at 
> org.apache.axis2.databinding.utils.ConverterUtil.serializeAnyType(ConverterUtil.java:1449)
>       at 
> org.tempuri.test.data.arrays.xsd.ArrayOfanyType.serialize(ArrayOfanyType.java:241)
>       at 
> org.tempuri.test.data.arrays.xsd.ArrayOfanyType.serialize(ArrayOfanyType.java:160)
>       at 
> org.tempuri.test.RetArrayAnyType1D.serialize(RetArrayAnyType1D.java:203)
>       at 
> org.tempuri.test.RetArrayAnyType1D.serialize(RetArrayAnyType1D.java:123)
>       at 
> org.tempuri.test.RetArrayAnyType1D$1.serialize(RetArrayAnyType1D.java:111)
> ...
> I did not have this problem on Axis2 1.3 so I guess something have been 
> changed in ConverterUtil.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to