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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:00:47+00:00 2026-06-17T09:00:47+00:00

How to convert generic list to json in Java.I have class like this.. public

  • 0

How to convert generic list to json in Java.I have class like this..

public class Output
{
    public int Keyname { get; set; }
    public Object  outputvalue{ get; set; }  //outvalue may be even a object collection
}

List<Output> outputList = new List<Output>();

I want to convert outputList into json in Java.After converting i will send it to client.

  • 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-17T09:00:48+00:00Added an answer on June 17, 2026 at 9:00 am

    Use GSON library for that. Here is the sample code

    List<String> foo = new ArrayList<String>();
    foo.add("A");
    foo.add("B");
    foo.add("C");
    
    String json = new Gson().toJson(foo );
    

    Here is the maven dependency for Gson

    <dependencies>
        <!--  Gson: Java to Json conversion -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.2</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    

    Or you can directly download jar from here and put it in your class path

    http://code.google.com/p/google-gson/downloads/detail?name=gson-1.0.jar&can=4&q=

    To send Json to client you can use spring or in simple servlet add this code

    response.getWriter().write(json);

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

Sidebar

Related Questions

I have a web service that looks like this [WebMethod] public int Import(System.Collections.Generic.List<Record> importRecords)
I have this error: Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List' For the following
I have a Generic list of a class that I automatically convert it to
Why do I get this error message: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.List'
The following code gives me this error: Cannot convert from 'System.Collections.Generic.List' to 'System.Collections.Generic.List'. How
I have an object, want to convert the generic object to class object. I
I am getting this error. Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<ModelBase.IModel>' to 'System.Collections.Generic.List<ModelBase.User>'
I have a compiler error when trying to set a generic base collection class
I get an error of Cannot convert object of type System.String' to type 'System.Collections.Generic.List'1[...+ContactHolder]'
I need to convert from object {object[]} to System.Collections.Generic.List<int> Inside each element in the

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.