Sharing Java classes between web service and client side

I am programming an Android application as my final project. It connects to java web service in the cloud. My problem is that I want to use complex Java objects and share them between my Android application and my web service in the cloud.

As an example, I have a class “Mission”, and I want to use methods that introduce an argument of type “Mission” as a parameter or return a type of “Mission”. I want to use these complex objects just like String, Integer or Boolean.

Is it possible to create a library file or jar or something that contains these classes on the client side and server side?

What should I do to use these classes and complex Java objects between the server and client side, just like we use String or other regular Java types?

+4
source share
1 answer

The best method is to use JSON. It cannot transmit 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();

:

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

0
source

Source: https://habr.com/ru/post/1611413/


All Articles