mw88
mw88

Reputation: 499

What is the best way to get Objects from the Server through HTTP?

I need to read a List (or Object in general) from the HttpResponse but I get an exception without a message.

What is the best way to get Objects from the server through http?

My implementation does not work:

List projectList = new ArrayList();
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url+"&action=getProjectList");
HttpResponse response = client.execute(request);

Object obj = null;
InputStream inputStream = response.getEntity().getContent();

// This is where the exception occurs
ObjectInputStream responseObject = new ObjectInputStream(inputStream);

if ((obj = responseObject.readObject()) != null)
{
    projectList = (List) obj;
}

Upvotes: 0

Views: 161

Answers (1)

Matthias
Matthias

Reputation: 240

I would serialize the objects as XML/JSON/... on the server, send them in a HTTP response and finally deserialize them on the Android client. There exist several libraries (which work also in Android) to automatically serialize/deserialize objects, e.g. XStream (http://code.google.com/p/xstream-for-android/), Simple (http://simple.sourceforge.net/), Jackson (http://jackson.codehaus.org/), ...

Upvotes: 1

Related Questions