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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:05:01+00:00 2026-06-05T06:05:01+00:00

Possible Duplicate: deserializing generics with gson So I need to do: Type fluentType =

  • 0

Possible Duplicate:
deserializing generics with gson

So I need to do:

Type fluentType = new TypeToken<BruteForceFluentImpl<GtlDigestor.Data>>() {}.getType();

instead of

Type fluentType = new TypeToken<Fluent<T>>() {}.getType(); // <-- i want to be able to do something like this.

String json = gson.toJson(fluent, fluentType);

This means that every time I have to specify a different type parameter for the Fluent class, I need to change my code in order to specify it. Right now, the type parameter is GtlDigestor.Data.

How do I do this? (the second line of code won’t work)

  • 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-05T06:05:03+00:00Added an answer on June 5, 2026 at 6:05 am

    You need to tell Gson the actual parameterized type (e.g. BruteForceFluentImpl<GtlDigestor.Data>, including the actual runtime raw type and the actual type parameter value) at runtime, because Gson needs to save this information.

    Using TypeToken is the easiest way to get a Type, but to use it you must hard-code the exact type in the source (no type parameters like T). If you would like to put the code in a method that will be re-used with different types, then perhaps this method should accept the Type as a parameter, which the caller needs to pass in. The type can then be hard-coded at the caller’s location, each of which presumably only uses a fixed type.

    Or, if you need to generate the Type completely dynamically at runtime based on the raw type and type parameters, see my answer for the question here.

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

Sidebar

Related Questions

Possible Duplicate: New Cool Features of C# 4.0 Hello, There are several(many) questions at
Possible Duplicate: Deserializing JSON into an object with Json.NET Any ideas of how to
Possible Duplicate: Deserializing XML, how do I access attributes? I am deserializing the following
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Turning on camera flash LED in Android? I need to turn on
Possible Duplicate: Opening url in new tab while i am doing window.open(), my page
Possible Duplicate: What is the fastest XML parser in PHP? I still need to
Possible Duplicate: Python : how to append new elements in a list of list?
Possible Duplicate: Yield In VB.NET In C#, when writing a function that returns an
Possible Duplicate: Best way to stop SQL Injection in PHP I am creating a

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.