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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:25:44+00:00 2026-06-16T01:25:44+00:00

I have figured out that my GSON problems are all about the fact that,

  • 0

I have figured out that my GSON problems are all about the fact that, while my return type is not a parameterized object, it should have been. Now I need to use the Gson.fromJson method with the type of parameter to specify the return type so that GSON will take care of it for me.

I have created a generic class called RestResponse such:

public class RestResponse<T> {
  private   String      errorMessage;
  private   int         errorReason;
  private   T           result;

  /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString() {
    return "RestResponse [errorMessage=" + errorMessage + ", result=" + result + "]";
  }

  /**
   * Does this response contain an error?
   * @return true if in error
   */
  public boolean isInError(){
    return getErrorMessage()!=null;
  }

  /**
   * @return the errorMessage
   */
  public String getErrorMessage() {
    return errorMessage;
  }

  /**
   * @param errorMessage the errorMessage to set
   */
  public void setErrorMessage(String errorMessage) {
    this.errorMessage = errorMessage;
  }

  /**
   * The error reason code
   * @return the errorReason
   */
  public int getErrorReason() {
    return errorReason;
  }

  /**
   * The error reason code
   * @param errorReason the errorReason to set
   */
  public void setErrorReason(int errorReason) {
    this.errorReason = errorReason;
  }

  /**
   * The result of the method call
   * @return the result or null if nothing was returned
   */
  public final T getResult() {
    return result;
  }

  /**
   * The result of the method call
   * @param result the result to set or null if nothing was returned
   */
  public final void setResult(T result) {
    this.result = result;
  }
}

Now I want to create the resulting type on the other side. I have a generic method that I use to decode these things and either throw the exception or return the result.

So my method is like this:

public Object submitUrl(String url, Class<?> clazz) throws AjApiException {

Where clazz is the type that will be specified on RestResponse.

I then go to create the RestResponse before passing to GSON:

Type typeOfT = new TypeToken<RestResponse<clazz>>(){}.getType(); //1-->What goes here?
RestResponse<clazz> restResponse; //2-->and here?

And it errors. Can someone tell me what goes in these to places in place of clazz?

  • 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-16T01:25:46+00:00Added an answer on June 16, 2026 at 1:25 am

    I ended up passing in the type instead of the class. This solved the problem.

    I believe you can create the type by doing something like:

    Type typeOfT = new TypeToken<RestResponse<T>>(){}.getType();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've figured out a way to cache data (so that I won't have to
I have figured out that I can use hibernate to get the sum of
I have figured out that to integrate calls between Apache HTTP server and Restlet,
Thanks to the answers I have figured out that I am unable to use
I have model data that came from a MultipleChoiceField. I have figured out it
I have just entered in the world of OpenX, and as figured out that
I have a regular expression which has multiple matches. I figured out that $1
So far, I have figured out how to return a typical JSON response in
I have figured out that I must use ioctl. There are similar questions here:
Question update: I have figured out that importing JQuery (even without using it at

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.