int[] intArray = {1, 2, 3}; Integer[] integerArray = new Integer[intArray.length]; for (int i = 0; i < intArray.length; i++) { integerArray[i] = Integer.valueOf(intArray[i]); } PropertyInfo propertyInfo = new PropertyInfo(); propertyInfo.setName("intArray"); propertyInfo.setValue(integerArray); propertyInfo.setType(integer[].class); soapRequest.addProperty(propertyInfo);
public class IntArraySerializer extends MarshalBase64 {
@Override
public Object[] readInstance(XmlPullParser parser, String namespace, String name, PropertyInfo info)
throws IOException, XmlPullParserException {
return Base64.decode(parser.nextText(), Base64.DEFAULT);
}
@Override
public void writeInstance(XmlSerializer writer, Object[] obj) throws IOException {
writer.text(Base64.encodeToString((int[]) obj, Base64.DEFAULT));
}
@Override
public void register(SoapSerializationEnvelope envelope) {
envelope.addMapping(envelope.xsd, "intArray", int[].class, this);
}
}
// 在请求中设置属性 int[] intArray = {1, 2, 3}; PropertyInfo propertyInfo = new PropertyInfo(); propertyInfo.setName("intArray"); propertyInfo.setValue(intArray); propertyInfo.setType(int[].class); propertyInfo.setPropertyMarshal(new IntArraySerializer()); soapRequest.addProperty(propertyInfo);
需要注意的是,在使用自定义序列化器时,需要在注册前先为请求设置envelope.dotNet = true。