4

I'm programming android app as my final project. It's connecting to a java web-service on cloud. My problem is that I want to use complex java objects and share them between my android app and my web service on cloud.

As example I have "Mission" class and i want use methods that get "Mission" type argument as parameter, or returns "Mission" type. I want to use those complex objects just as String, Integer or Boolean.

May I create a library or jar file or something that hold those classes on the client side and the server side?

What should I do to use those classes and complex java objects between the server-side and the client-side just as we use String or other regular java types?

  • RESTful web service complex object as argument - http://stackoverflow.com/a/6292702/4807777 – Laurentiu L. Oct 13 '15 at 11:46
  • do you mean that you want not to create a library or jar file or something that hold those classes on the client side and the server side? – xxxzhi Oct 13 '15 at 12:34
  • or you want share object like example of Retrofit about request body - http://square.github.io/retrofit/ – xxxzhi Oct 13 '15 at 12:38
  • Implement `Serializable` interface and use `ObjectInputStream` and `ObjectOutputStream` to write and read objects. More here: http://stackoverflow.com/questions/14969461/serializing-over-http-correct-way-to-convert-object – eleven Oct 13 '15 at 12:39
  • I want create a method from the web-service that returns multiple values. I mean like I have Mission class that have id number (int), name (string), etc. then from the android application i will get those values and put them all into a class named "Mission" too. If i could make a library or jar file for hold those classes and then use them between the server-side and the client-side.. just as i'm using String or Integer etc. I think that could be amazing! – Yotam Noy Levy Oct 13 '15 at 14:59

1 Answers1

0

The best method is using JSON. That it can not transfer all the data.

              URL url = new URL("Your Web Service URL");

              // Send POST data request

              URLConnection conn = url.openConnection(); 
              conn.setDoOutput(true); 
              OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); 
              wr.write( data ); 
              wr.flush(); 

              // Get the server response 

              reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
              StringBuilder sb = new StringBuilder();
              String line = null;

                // Read Server Response
                while((line = reader.readLine()) != null)
                    {
                           // Append server response in string
                           sb.append(line + "");
                    }

                // Append Server Response To Content String 
               Content = sb.toString();

sample :

http://androidexample.com/Restful_Webservice_Call_And_Get_And_Parse_JSON_Data-_Android_Example/index.php?view=article_discription&aid=101&aaid=123

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
  • thank you very much! but what should be the method on the web-service? how should I use it to send multiple values (in different types) from the web-service to the android app? (in one method of course) – Yotam Noy Levy Oct 13 '15 at 15:08