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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:27:53+00:00 2026-06-17T11:27:53+00:00

I am using GSON library for turing JSON that comes form a web service

  • 0

I am using GSON library for turing JSON that comes form a web service but I can’t make it work, I always get a null. I’ve looked through similar issues like Converting Json to Java such as Simple Json to Java convertion using GSON. But I am still missing something

JSON

{"A":"val1","B":"val2","C":"val3","D":"val4","E":"val5","F":"val6","G":"val7"}
         SiteWrapper m = gson.fromJson(json, SiteWrapper.class);

java Class

SiteWrapper m = gson.fromJson(json, SiteWrapper.class);
System.out.println(m.getMenu());

static class Site {
    static String A;
    static String B;
    static String C;
    static String D;
    static String E;
    static String F;
    static String G;

    public String toString() {
        return String.format(A,B,C,D,E,F,G);}

    public static String getA() {
        return A;
    }
    public static String getB() {
        return B;
    } 
... all the way to getG

    public void setA(String A) {
        Site.A = A;
    }
    public void setB(String B) {
        Site.B = B;
    }
... all the way to setB

and my wrapper

class SiteWrapper {
    private Site site;
    public Site getMenu() { return site; }
    public void setMenu(Site site) { this.site = site; }
}

no matter what I do I get a null printed , any ideas?

  • 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-17T11:27:53+00:00Added an answer on June 17, 2026 at 11:27 am

    Since its a static inner class .As docs pointed out and comments :

    As well, if a field is marked as “static” then by default it will be
    excluded. If you want to include some transient fields…

    You may want to try

     Gson gson = new GsonBuilder()
        .excludeFieldsWithModifier()
        .create();
    

    Also, since its a inner class you may need to change your JSON If you can:

     {
       "site":{
          "A":"val1",
          "B":"val2",
          "C":"val3",
          "D":"val4",
          "E":"val5",
          "F":"val6",
          "G":"val7"
       }
    }
    

    As noted here in this post

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently started using GSON library for deserializing JSON that comes from web service
I am using JSON-Lib library to do JSON encoding. Can't do it with GSON
I am using the Gson library to make Json objects. I made a serializer
I am using Gson library to convert objects to Json and vice versa. I
I am trying to convert an object into JSON using the GSON library on
Suppose I am using Google's Gson library to parse JSON into Java data structures.
Hi i am trying to parse Json using gson library.My Json String is this
I'm using the Gson library in Java to serialize java objects to jSon and
I'm using Google's GSON Library to convert JSON data to Java objects. The issue
I'm using the GSON 1.7.1 library to create a JSON representation of a number

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.