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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:08:42+00:00 2026-05-15T19:08:42+00:00

class Json<T> { @SerializedName( T’s type here ) private final ArrayList<T> _bucket = new

  • 0
class Json<T>
{
  @SerializedName( "T's type here" ) 
  private final ArrayList<T> _bucket = new ArrayList<T>( 5 );
  ...
}

I’d like to know how (if possible) the generic parameters of a class can be determined at run-time. From what I’ve read this is possible with sub-classes of generic types, but I haven’t been able to find out how to do it with the type itself. There’s some great info in these links, but I’m not sure it’s what I’m looking for.

http://blog.xebia.com/2009/02/07/acessing-generic-types-at-runtime-in-java
http://www.artima.com/weblogs/viewpost.jsp?thread=208860

What I’m ultimately trying to accomplish, is to get Gson to serialize the ‘_bucket’ variable above, as the class name of type ‘T’.

I’d appreciate it if someone could point me in the right direction.

  • 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-15T19:08:43+00:00Added an answer on May 15, 2026 at 7:08 pm

    The generic type is not available at runtime in the given example. Generic type information is only available via reflection if it was specified at compile-time—for example, if you defined a subclass SomeTypeJson extends Json<SomeType>.

    As a kludge, you could guess at the generic type by examining the contents of the List, finding the most specific common superclass via reflection.

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

Sidebar

Related Questions

Id like to represent a Class object as JSON. For example, if I have
I would like to serialize this object to JSON String public class Person {
I’m new to android,I have an activity class which fetches Json string from url
Given some code like this: class Json { } class Program { static void
I would like to use this kind of Objects with json: class Message{ int
JSON Parser Class public class JSONParser { static InputStream is = null; static JSONObject
I have a JSON helper class. I have been trying to to display a
Is there a JSON query class or jQuery plugin that I can use to
This is my code: import play.api.mvc._ import play.api.libs.json._ import play.api.libs.json.Json._ import play.api.libs.json.Writes._ class BaseController
I have a class like so: [JsonObject(MemberSerialization.OptIn)] public class foo { [JsonProperty(name_in_json)] public string

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.