MessageWriter cwriter = writer.getElementWriter(type.getSchemaType().getLocalPart(), "");
if (value == null && type.isNillable()) {
// null
cwriter.writeXsiNil();
} else if (type instanceof BeanType || type instanceof SoapArrayType) {
// write refs to complex type
String refId = MarshalRegistry.get(context).getInstanceId(value);
SoapEncodingUtil.writeRef(cwriter, refId);
} else {