Search code examples
androidweb-servicesserializationbitmapandroid-ksoap2

Android cannot serialize byte[] recieved from compressed BMP


The code

Bitmap bmp = (Bitmap)extras.get("data");
ByteArrayOutputStream out = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 100, out);
byte[] raw = out.toByteArray();
PassToWebservice(raw); //error

PassToWebservice(byte[] ba)
{
   SoapObject envelope...
   envelope.addProperty("base64bytes", ba);
   ...
   transport.call(ACTION, envelope);
   envelope.getResponse() //error: IOException cannot serialize...
}

The problem
When I pass the compressed image to my webservice, I get a runtimeexception that says "cannot serialize [B@47bcb6c8..." Something is not apparent to me, can anyone see why the above (psuedo) code does not work? If it helps, on the webservice server side, the exception seems to be happening when the server writes the passed bytes to a file (using .Net IO.File.WriteAllBytes)

Stack trace
enter image description here


Solution

  • I needed to do this:

    MarshalBase64 marshal;
    marshal.register(envelope);