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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:40:50+00:00 2026-05-17T17:40:50+00:00

I was wondering, given the following JSON, how I can produce a ResultSet instance,

  • 0

I was wondering, given the following JSON, how I can produce a ResultSet instance, which carry Query valued ppb?

package jsontest;

import com.google.gson.Gson;

/**
 *
 * @author yccheok
 */
public class Main {

    public static class ResultSet {
        public String Query;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        final String s = "{\"ResultSet\":{\"Query\":\"ppb\"}}";
        System.out.println(s);
        Gson gson = new Gson();
        ResultSet resultSet = gson.fromJson(s, ResultSet.class);
        // {}
        System.out.println(gson.toJson(resultSet));
        // null?
        System.out.println(resultSet.Query);
    }
}

Currently, here is what I get :

{"ResultSet":{"Query":"ppb"}}
{}
null

Without modified the String, how can I get a correct Java object?

  • 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-05-17T17:40:51+00:00Added an answer on May 17, 2026 at 5:40 pm

    Try first to construct a new object, call gson.toJson(object), and see the result.

    I don’t have gson, but jackson (another object-to-json mapper) prints this:

    {"Query":"ppb"}
    

    So, you don’t include the class name. Actually, the gson user guide gives an example showing exactly this. Look at the BagOfPrimitives.

    (And a final note – in Java, the accepted practice is that variables are lowercase – i.e. query rather than Query)

    Update If you really can’t change the json input, you can mirror the structure this way:

    public static class Holder {
        public ResultSet ResultSet;
    }
    
    public static class ResultSet {
        public String Query;
    }
    

    (and then use Holder h = gson.fromJson(s, Holder.class);)

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

Sidebar

Related Questions

I'm just wondering if Specification pattern is pointless, given following example: Say you want
I was just wondering how does the container select which package to load a
given the following arrays in php, how can i best merge them together $masterkeys
I am wondering how the HttpContext is maintained given that the request-response nature of
Given a large legacy project utilizing ASP.NET, javascript, css, etc, technologies, I was wondering
I'm wondering how you'd recommend designing a class, given the fact that XNA Framework
I'm just getting started/familar with Subversion and was wondering which protocol gives the best
Given the following string: var str = one,two,three; If I split the string on
Given the following piece of (pseudo-C++) code: float x=100, a=0.1; unsigned int height =
I am trying to figure this out, given the following code, does the Refresh()

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.