I am trying to access a webservice via Axis and having problems with
registering my type mappings.
I have two different Lists that I need mapped: List<ObjectA> and
List<ObjectB>. However, I can only register one type mapping for
List.class. It only picks up the last one registered.
<code>
call.registerTypeMapping(java.util.List.class, objectAqname, new
ArraySerializerFactory(), new ArrayDeserializerFactory(hostqname));
call.registerTypeMapping(java.util.List.class, objectBqname, new
ArraySerializerFactory(), new ArrayDeserializerFactory(hostqname));
</code>
I am stumped and would appreciate any and all help. Please let me know
if you need more info.
Thanks.
I think this is how it has to be considering type erasure.
If you return ObjectA[] and ObjectB[] then I think you can
do it.
Arne
>> I have two different Lists that I need mapped: List<ObjectA> and
>> List<ObjectB>. However, I can only register one type mapping for
>> List.class. It only picks up the last one registered.
>>
>> <code>
>> call.registerTypeMapping(java.util.List.class, objectAqname, new
>> ArraySerializerFactory(), new ArrayDeserializerFactory(hostqname));
>>
>> call.registerTypeMapping(java.util.List.class, objectBqname, new
>> ArraySerializerFactory(), new ArrayDeserializerFactory(hostqname));
>> </code>
>
> I think this is how it has to be considering type erasure.
>
> If you return ObjectA[] and ObjectB[] then I think you can do it.
>
> Arne
Would wildcards help?
-Thufir
Wildcards ??
Arne
I dont know what you mean by wildcards either. And I cannot return
ObjectA[] or ObjectB[]. I am actually returning a different object,
ObjectC, which has two properties, List<ObjectA> and List<ObjectB>.
Make an ObjectCExternal that contains ObjectA[] and ObjectB[].
Arne
"
public void drawAll(List<? extends Shape> shapes) { ... }
There is a small but very important difference here: we have replaced
the type
List<Shape> with List<? extends Shape>. Now drawAll() will accept lists of
any subclass of Shape, so we can now call it on a List<Circle> if we
want."
Generics in the Java Programming Language
Gilad Bracha
July 5, 2004
page 6
Instead of List<ObjectA> how about List<? extends ParentOfAB>. Or not?
-Thufir
Hmmmmm, That is something I will consider.
But why do I have to register the List class anyway? The WSDL defines
a type "ArrayOfObjectA", why will it not work to register ObjectA[]?
What is the error when you try it?
--
Lew
I get a NullPointerException when it tries to deserialize
ArrayOfObjectA as ObjectA[].
I can get past this point by registering ArrayOfObjectA with
List.class...
<xsd:complexType name="ArrayOfMainObject">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="TraceRoute"
nillable="true" type="ns1:MainObject"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="MainObject">
<xsd:sequence>
<xsd:element minOccurs="0" name="id" nillable="true"
type="xsd:string"/>
<xsd:element minOccurs="0" name="objectA" nillable="true"
type="ns1:ArrayOfObjectA"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ArrayOfObjectA">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Hops"
nillable="true" type="ns1:ObjectA"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ObjectA">
<xsd:sequence>
<xsd:element minOccurs="0" name="id" nillable="true"
type="xsd:string"/>
<xsd:element minOccurs="0" name="objectB" nillable="true"
type="ns1:ArrayOfObjectB"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ArrayOfObjectB">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Host"
nillable="true" type="ns1:ObjectB"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ObjectB">
<xsd:sequence>
<xsd:element minOccurs="0" name="hostId" nillable="true"
type="xsd:string"/>
<xsd:element minOccurs="0" name="field1" nillable="true"
type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>