Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8856729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:25:16+00:00 2026-06-14T14:25:16+00:00

What are good practice for handling json over a Rest Framework in Android. For

  • 0

What are good practice for handling json over a Rest Framework in Android. For instance, if I get a certain json result as follow (or any other, I’m just giving something more complex):

{"lifts": 
[{
   "id":26,
   "time":"2012-11-21T12:00:00Z",
   "capacity":4,
   "price":10,
   "from": { 
            "description":null,
            "city": {
                      "name":"Montreal"
                    }
           },
    "to":{
           "description":"24 rue de la ville",
           "city":{
                   "name":"Sherbrooke"
                  }
          },
    "driver":{
              "first_name": "Benjamin",  
              "image":"https://graph.facebook.com/693607843/picture?type=large"
             }
    }
]}

1) Should I handle the result manually and get each value to populate my ui… (Not really)

2) Should I create a POJO for each object (to handle the mapping, with JSONObject). In my example, I will have to create a lift object that handle all the parameters and even create more POJO, to use for instance image and probably locations. (so basically, I constantly need to check my api rest framework to see how my object are done on server side, I’m duplicating my models from server to the android client).

3) Is there any framework to handle the mapping (serialize and deserialization).

I’m currently using option number 2, but was wondering if there was something better out there. It’s working for me so far, for receiving and sending.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:25:17+00:00Added an answer on June 14, 2026 at 2:25 pm

    I like to create a response object per api endpoint where i map the response of the call.

    For the given example and using GSON, the response object would be something like the following

    public class Test
    {
        static String jsonString = 
        "{\"lifts\":" + 
        "   [{" +
        "      \"id\":26," +
        "      \"time\":\"2012-11-21T12:00:00Z\"," +
        "      \"capacity\":4," +
        "      \"price\":10," +
        "      \"from\": { " +
        "               \"description\":null," +
        "               \"city\": {" +
        "                         \"name\":\"Montreal\"" +
        "                       }" +
        "               }," +
        "        \"to\":{" +
        "               \"description\":\"24 rue de la ville\"," +
        "               \"city\":{" +
        "                       \"name\":\"Sherbrooke\"" +
        "                      }" +
        "              }," +
        "        \"driver\":{" +
        "                  \"first_name\": \"Benjamin\"," +  
        "                  \"image\":\"https://graph.facebook.com/693607843/picture?    type=large\"" +
        "                 }" +
        "        }" +
        "     ]}";
    
    
        public static void main( String[] args )
        {
            Gson gson = new Gson();
    
            Response response = gson.fromJson( jsonString, Response.class );
    
            System.out.println( gson.toJson( response ) );
        }
    
    
        public class Response
        {
            @SerializedName("lifts")
            List<Lift> lifts;
        }
    
        class Lift
        {
            @SerializedName("id")
            int id;
    
            @SerializedName("time")
            String time;
    
            @SerializedName("capacity")
            int capacity;
    
            @SerializedName("price")
            float price;
    
            @SerializedName("from")
            Address from;
    
            @SerializedName("to")
            Address to;
    
            @SerializedName("driver")
            Driver driver;
        }
    
        class Address
        {
            @SerializedName("description")
            String description;
    
            @SerializedName("city")
            City city;
        }
    
        class City
        {
            @SerializedName("name")
            String name;
        }
    
        class Driver
        {
            @SerializedName("first_name")
            String firstName;
    
            @SerializedName("image")
            String image;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any good practice related to dynamic_cast error handling (except not using it
Is there any good practice for this? I wish I could solve the problem
What is a good error handling practice for an asp.net site? Examples? Thanks!
Anyone have any good tips on handling differences in web.config settings between environments? I've
Adding Exceptional Handling is a good practise, but I have a doubt, In our
I am looking for good practice or pattern to write a lib in JS.
Is it a good practice to have multiple XXX : DbContext classes for each
Is it good practice to use custom error levels on trigger_error() ? For example,
I know it is good practice to keep your website entirely 'http://www' or http://,
Is it good practice to set all text fields to nvarchar(MAX)? if im not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.