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 RK...@MICROS.COM on 2002/08/05 21:37:32 UTC
Use of ArrayDeserializer in Custom Deserializer
Does anyone know how to deserialize an array within a custom deserializer?
My serializer is as follows:
public class TaxInformationVOSerializer implements Serializer
{
public static final QName myTypeQName = new QName("myofficeNS",
"TaxInformationVO");
public void serialize(QName name, Attributes attributes, Object value,
SerializationContext context)
throws IOException
{
if (!(value instanceof TaxInformationVO))
{
throw new IOException("Can't serialize a " +
value.getClass().getName() + " with a " + this.getClass().getName());
}
TaxInformationVO data = (TaxInformationVO) value;
context.startElement(name, attributes);
context.serialize(new QName("", "taxInformationId" ), null,
data.getTaxInformationId() , Long.class);
context.serialize(new QName("", "addWithholdingAmtState" ), null,
data.getAddWithholdingAmtState() , BigDecimal.class);
// Convert TaxProgramAssignments collection to typed array
Collection taxProgramAsgnCol =
data.getTaxProgramAssignments();
TaxProgramAssignmentVO[] classArray = new
TaxProgramAssignmentVO[0];
TaxProgramAssignmentVO[] taxProgramAsgnArray = null;
// Remember .NET prefers empty arrays as null
if (taxProgramAsgnCol.size() > 0)
{
taxProgramAsgnArray = new
TaxProgramAssignmentVO[taxProgramAsgnCol.size()];
taxProgramAsgnCol.toArray(taxProgramAsgnArray);
}
context.serialize(new QName("", "taxProgramAssignments"), null,
taxProgramAsgnArray, classArray.getClass());
context.endElement();
}
public String getMechanismType() { return Constants.AXIS_SAX; }
public boolean writeSchema(Types types) throws Exception
{
return false;
}
}
This code will property serial an object for transmission between an AXIS
Beta 3 Webservice and a .NET client.
My problem is deserializing the result from the client.
Here is my deserializer:
public class TaxInformationVODeserializer extends DeserializerImpl
{
public static final QName myTypeQName = new QName("myofficeNS",
"TaxInformationVO");
private Hashtable typesByMemberName = new Hashtable();
public TaxInformationVODeserializer()
{
typesByMemberName.put("taxInformationId" ,
Constants.XSD_LONG);
typesByMemberName.put("employeeId" ,
Constants.XSD_LONG);
typesByMemberName.put("addWithholdingAmtState" ,
Constants.XSD_DECIMAL);
typesByMemberName.put("taxProgramAssignments" ,
Constants.SOAP_ARRAY);
value = new TaxInformationVO();
}
public SOAPHandler onStartChild(String namespace, String localName,
String prefix,Attributes attributes,DeserializationContext context)
throws SAXException
{
QName typeQName = (QName)typesByMemberName.get(localName);
if (typeQName == null)
throw new SAXException("Invalid element in " +
value.getClass().getName() + " - " + localName);
// Thesew can come in either order.
Deserializer dSer = context.getDeserializerForType(typeQName);
try
{
dSer.registerValueTarget(new FieldTarget(value, localName));
}
catch (NoSuchFieldException e)
{
throw new SAXException(e);
}
if (dSer == null)
{
throw new SAXException("No deserializer for a " + typeQName +
"???");
}
return (SOAPHandler) dSer;
}
}
Any ideas why I cannot deserialize the array. It is a typed array of value
objects and the value object has been registered in the WSDD file.
Thanks,
Rick Kellogg