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 8866171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:43:15+00:00 2026-06-14T16:43:15+00:00

I’m trying to parse a JSON with GSON library on my Android App. I

  • 0

I’m trying to parse a JSON with GSON library on my Android App. I could parse correctly a JSON Array, but now I need to parse another json, with this estructure:

    {
    "articles": [
        {
            "article": {
                "articleId": 1,
                "articleName": "Bocadillo de calamares",
                "merchantId": 2,
                "price": 3.5
            },
            "computable": true,
            "orderArticleId": 3157,
            "orderId": 203,
            "price": 3.5,
            "requestedDate": "2012-11-19 13:15:20",
            "shared": true,
            "status": "AS01_INITIAL"
        },
        {
            "article": {
                "articleId": 3,
                "articleName": "Desayuno",
                "merchantId": 2,
                "price": 2.2
            },
            "computable": true,
            "orderArticleId": 3158,
            "orderId": 203,
            "price": 0,
            "requestedDate": "2012-11-19 13:17:30",
            "shared": true,
            "status": "AS01_INITIAL"
        },
        {
            "article": {
                "articleId": 2,
                "articleName": "Café",
                "merchantId": 2,
                "price": 1.1
            },
            "computable": true,
            "orderArticleId": 3156,
            "orderId": 203,
            "price": 1.1,
            "requestedDate": "2012-11-19 13:15:20",
            "shared": true,
            "status": "AS01_INITIAL"
        },
        {
            "article": {
                "articleId": 1,
                "articleName": "Bocadillo de calamares",
                "merchantId": 2,
                "price": 3.5
            },
            "computable": true,
            "orderArticleId": 3155,
            "orderId": 203,
            "price": 3.5,
            "requestedDate": "2012-11-19 12:40:17",
            "shared": true,
            "status": "AS01_INITIAL"
        }
    ],
    "comment": null,
    "creationDate": "2012-11-19 12:06:41",
    "customer": {
        "creationDate": 1353321506000,
        "customerId": 152,
        "devices": [
            {
                "customerId": 152,
                "deviceId": "2000",
                "phone": null
            }
        ],
        "image": false,
        "mail": null,
        "name": null,
        "password": null
    },
    "finishDate": null,
    "group": 0,
    "groupOrders": [],
    "location": {
        "location": "Table 1",
        "locationId": 1,
        "shopId": 2
    },
    "orderId": 203,
    "parentOrderId": 192,
    "score": null,
    "shopId": 2,
    "status": "OS01_INITIAL",
    "ticketUrl": null,
    "tip": null,
    "total": 0,
    "totalArticles": 0,
    "type": "BILL"
}


I have a Order.class like this:

    public class Order {

    private final String orderId;
    (....)
    private final ArrayList<Articles> articles;
    private final String group;


    public Order() {

        orderId = "";
         (....)

        articles = new ArrayList<Articles>();
        group = "";
    }

    public String getOrderId() {
        return orderId;
    }

     (... All getters for each element)

    public ArrayList<Articles> getArticles() {
        return articles;
    }
}

And a Articles.class

public class Articles {

private final String orderArticleId;
(...)
private final ArrayList<Article> article;

public Articles() {
    orderArticleId = "";
    (....)
    article = new ArrayList<Article>();

};

public String getPrice() {
    return price;
}

(....All getters for each element)

public ArrayList<Article> getArticle() {
    return article;
}

}

And, on my main activity I try to get all the info whith this:

    final Gson gson = new Gson();
    Order o = gson.fromJson(jsonData, Order.class);
    System.out.println(" - " +  o.getOrderId() );

And works ok, but if I want to get Articles info, the values are null, and I don’t know how can I get it.

I try with something like that:

 Type collectionType = new TypeToken<List<Merchants>>() {
            }.getType();
            data = gson.fromJson(response, collectionType);

And I try to use a ArticlesWrapper, but I don’t know how to do it exactly.
But I think I forgetting something… and I don’t know what.
In another part of the app, I deserialize correctly a JSON because it is an Array, but on this case I don’t know how can I get all the data correctly.

If you need more information, I will provide you!.
Thanks!

  • 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-14T16:43:17+00:00Added an answer on June 14, 2026 at 4:43 pm

    This is because you are not translating correctly the JSON structure to Java POJOs, basically omitting some fields you have the following structure.

    + Order
        + List<BigArticle> articles
        + Customer customer
        + Location location
        + other basic fields
    
    + BigArticle
        + Article article
        + other basic fields
    
    + Article
        + basic fields
    
    + Customer
        + List<Device> devices
        + other basic fields
    
    + Device
        + basic fields
    
    + Location
        + basic fields
    

    So you should end up with 6 Java POJOs that GSon should be able to populate while deserializing the JSON data.

    I just translated your JSON structure to POJO here, and I’ve let Dates as String to simplify the parsing. If you want to have java.util.Date populated correctly you will have to customize the GSon instance.

    Main class

    public class Main {
        public static void main(String[] args) {
            String jsonData = "...";
            final Gson gson = new Gson();
            Order o = gson.fromJson(jsonData, Order.class);
            System.out.println("orderId: " +  o.getOrderId());
            System.out.println("first article price: " + o.getArticles().get(0).getPrice());
            System.out.println("second article status: " + o.getArticles().get(1).getStatus());
            System.out.println("third article requested date: " + o.getArticles().get(2).getRequestedDate());
        }
    }
    

    Order

    public class Order {
        private List<BigArticle> articles;
        private String comment;
        private String creationDate;
        private Customer customer;
        private String finishDate;
        private int group;
        private List<Integer> groupOrders;
        private Location location;
        private int orderId;
        private int parentOrderId;
        private int score;
        private int shopId;
        private String status;
        private String ticketUrl;
        private String tip;
        private int total;
        private int totalArticles;
        private String type;
    
        // getters and setters
    }
    

    BigArticle

    public class BigArticle {
        private Article article;
        private boolean computable;
        private int orderArticleId;
        private int orderId;
        private double price;
        private String requestedDate;
        private boolean shared;
        private String status;
    
        // getters and setters
    }
    

    Article

    public class Article {
        private int articleId;
        private String articleName;
        private int merchantId;
        private double price;
    
        // getters and setters
    }
    

    Customer

    public class Customer {
        private long creationDate;
        private int customerId;
        private List<Device> devices;
        private boolean image;
        private String mail;
        private String name;
        private String password;
    
        // getters and setters
    }
    

    Device

    public class Device {
        private int customerId;
        private String deviceId;
        private String phone;
    
        // getters and setters
    }
    

    Location

    public class Location {
        private String location;
        private int locationId;
        private int shopId;
    
        // getters and setters
    }
    

    Output

    orderId: 203
    first article price: 3.5
    second article status: AS01_INITIAL
    third article requested date: 2012-11-19 13:15:20
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,

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.