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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:58:10+00:00 2026-05-23T05:58:10+00:00

I am tring to map json data using Gson from a URL to my

  • 0

I am tring to map json data using Gson from a URL to my java class. This is the code for the class:

public class Sessions {
public Boolean active;
public String contributor_covu_id;
public String created_at;
public String key;
public String status;

public Boolean getActive() {
    return active;
}
public void setActive(Boolean active) {
    this.active = active;
}
public String getContributor_covu_id() {
    return contributor_covu_id;
}
public void setContributor_covu_id(String contributor_covu_id) {
    this.contributor_covu_id = contributor_covu_id;
}
public String getCreated_at() {
    return created_at;
}
public void setCreated_at(String created_at) {
    this.created_at = created_at;
}
public String getKey() {
    return key;
}
public void setKey(String key) {
    this.key = key;
}
public String getStatus() {
    return status;
}
public void setStatus(String status) {
    this.status = status;
}
public String getType() {
    return type;
}
public void setType(String type) {
    this.type = type;
}
public String type;

}

and this is the code of the class that calls the service and maps json

public static List<Sessions> getSessions(String urlString)
        throws IOException {

    Sessions[] sessions;
    List<Sessions> tempList = null;
    URL url = new URL(urlString);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    GsonBuilder gsonb = new GsonBuilder();
    Gson gson = gsonb.create();
    StringBuilder sb = new StringBuilder();
    String line;

    // Response response = null;
    JSONObject j = null;

    if (conn.getResponseCode() != 200) {
        throw new IOException(conn.getResponseMessage());
    }

    BufferedReader bufferedReader = new BufferedReader(
            new InputStreamReader(conn.getInputStream()));

    while ((line = bufferedReader.readLine()) != null) {
        sb.append(line);
    }
    bufferedReader.close();
    conn.disconnect();

    try {
        j = new JSONObject(sb.toString());
        sessions = gson.fromJson(j.toString(), Sessions[].class);
        tempList = Arrays.asList(sessions);

        // response = gson.fromJson(j.toString(), Response.class);
        // tempList.add(response);

    } catch (JSONException e) {
        e.printStackTrace();
    }
    return tempList;
}

Although the code is correct, I get a Gson exception “Unable to invoke no-args constructor for class com.test.Sessions;. Register an InstanceCreator with Gson for this type may fix this problem”

How do i solve this issue and return the Gson as an ArrayList?

  • 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-23T05:58:11+00:00Added an answer on May 23, 2026 at 5:58 am

    The solution is:

    public class Sessions {
    
    private String status;
    private List<Session> sessions;
    
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public List<Session> getSessions() {
        return sessions;
    }
    
    public void setSessions(List<Session> sessions) {
        this.sessions = sessions;
    }
    
    public static class Session {
        public Boolean active;
        public String contributor_covu_id;
        public String created_at;
        public String key;
        public String status;
        public String name;
    
    };
    

    }

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

Sidebar

Related Questions

i am using coredata and restkit to map data. here is the json response
I am trying to deserialize/map the below JSON to List<Bill > java object using
I'm using the SQLAlchemy recipe here to magically JSON encode/decode a column from the
what im trying to do is to send data in JSON using jquery to
I'm trying to parse json data from google directions but can't seem to access
For context, we are storing most of our data as JSON strings. This works
I'm trying to use Jackson to convert some JSON data into Java objects ,a
I am trying to validate one block of json data that I receive from
I'm trying to pass some lat/long values from a JSON doc to iPhone's Map
Trying to map the following schema using the Entity Framework. A Customer can have

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.