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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:59:02+00:00 2026-06-14T10:59:02+00:00

I am developing application in which i am use Gson parsing for serialize json

  • 0

I am developing application in which i am use Gson parsing for serialize json object which contain array of some data.. but here some issue with method that i am parse… it not getting me successfully parse.. i have never tried to parse json data with Gson library with Serialize annotation.can you please let me know where is my mistak…

here is code..

    InputStream source = retrieveStream(url);

    Gson gson = new Gson();

    Reader reader = new InputStreamReader(source);
    GetAllAssetsResult response = gson.fromJson(reader, GetAllAssetsResult.class);

   private InputStream retrieveStream(String url) {

    DefaultHttpClient client = new DefaultHttpClient(); 

    HttpGet getRequest = new HttpGet(url);

    try {

           HttpResponse getResponse = client.execute(getRequest);
           final int statusCode = getResponse.getStatusLine().getStatusCode();

           if (statusCode != HttpStatus.SC_OK) { 
              Log.w(getClass().getSimpleName(), 
                  "Error " + statusCode + " for URL " + url); 
              return null;
           }

           HttpEntity getResponseEntity = getResponse.getEntity();
           return getResponseEntity.getContent();

    } 
    catch (IOException e) {
       getRequest.abort();
       Log.w(getClass().getSimpleName(), "Error for URL " + url, e);
    }

    return null;

 }

here is Serialize annotaion base Pojo:

  package com.DemoGsonLib;

    import java.util.List;

    import com.google.gson.annotations.SerializedName;

        public class GetAllAssetsResult {

            public List<GetAllAssetsResult> getAllAssetsResult;

                @SerializedName("ATCOCode")
                public String ATCOCode;

                @SerializedName("AssetID")
                public String AssetID;

                @SerializedName("Bearing")
                public String Bearing;

                @SerializedName("CommonName")
                public String CommonName;

                @SerializedName("Locality")
                public String Locality;

                @SerializedName("Location")
                public String Location;

                @SerializedName("SMSNumber")
                public String SMSNumber;

                @SerializedName("Street")
                public String Street;
        }

Json Data :

{
  "GetAllAssetsResult": [
    {
      "ATCOCode": null,
      "AssetID": 1,
      "Bearing": null,
      "CommonName": null,
      "Locality": null,
      "Location": null,
      "SMSNumber": "Little Clare",
      "Street": null
    },
    {
      "ATCOCode": "34000000002",
      "AssetID": 2,
      "Bearing": null,
      "CommonName": "Gloucester Green Bus Station",
      "Locality": "Oxford City Centre",
      "Location": "50.4913",
      "SMSNumber": "oxfagwdw",
      "Street": "Gloucester Green"
    },
    {

Error

11-16 13:16:26.805: WARN/System.err(1762): java.lang.NullPointerException
11-16 13:16:26.805: WARN/System.err(1762):     at com.DemoGsonLib.DemoGsonLibActivity.onCreate(DemoGsonLibActivity.java:39)
11-16 13:16:26.805: WARN/System.err(1762):     at android.app.Activity.performCreate(Activity.java:4533)
11-16 13:16:26.805: WARN/System.err(1762):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
11-16 13:16:26.805: WARN/System.err(1762):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
11-16 13:16:26.805: WARN/System.err(1762):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
11-16 13:16:26.805: WARN/System.err(1762):     at android.app.ActivityThread.access$600(ActivityThread.java:128)
11-16 13:16:26.805: WARN/System.err(1762):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
11-16 13:16:26.805: WARN/System.err(1762):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-16 13:16:26.805: WARN/System.err(1762):     at android.os.Looper.loop(Looper.java:137)
11-16 13:16:26.805: WARN/System.err(1762):     at android.app.ActivityThread.main(ActivityThread.java:4517)
11-16 13:16:26.805: WARN/System.err(1762):     at java.lang.reflect.Method.invokeNative(Native Method)
11-16 13:16:26.805: WARN/System.err(1762):     at java.lang.reflect.Method.invoke(Method.java:511)
11-16 13:16:26.805: WARN/System.err(1762):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
11-16 13:16:26.805: WARN/System.err(1762):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
11-16 13:16:26.805: WARN/System.err(1762):     at dalvik.system.NativeStart.main(Native Method)
  • 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-14T10:59:03+00:00Added an answer on June 14, 2026 at 10:59 am

    You are not considering the fact that there’s a Json Array that need to be serialized in your pojo

    The following code should work

    public class GetAllAssetsResult
    {
        @SerializedName("GetAllAssetsResult")
        public List<Asset> assets;
    
        class Asset
        {
            @SerializedName("ATCOCode")
            public String ATCOCode;
    
            @SerializedName("AssetID")
            public String AssetID;
    
            @SerializedName("Bearing")
            public String Bearing;
    
            @SerializedName("CommonName")
            public String CommonName;
    
            @SerializedName("Locality")
            public String Locality;
    
            @SerializedName("Location")
            public String Location;
    
            @SerializedName("SMSNumber")
            public String SMSNumber;
    
            @SerializedName("Street")
            public String Street;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a soundboard application in which I use Listview Activity. But since
I am developing a soundboard application in which I use Listview Activity. But since
I'm developing an application which import a lot of data, in some paralells thread.
Some of the guys here are developing an application which incorporates some 'secure areas'
I'm developing ASP.net application which use web services. There are no data base connections
I'm developing an application which make use of display lists offered by OpenGL. My
I am developing an Android application which makes use of the Osmdroid maps api.
I am developing an application in which I want to use push notification service.
I am developing an application that contains 2 themes and pictures which i use
I am developing application which is having Gujarati font in text-view but my problem

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.