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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:43:13+00:00 2026-05-31T19:43:13+00:00

What I am trying to do is create a toJSONObject() method which returns the

  • 0

What I am trying to do is create a toJSONObject() method which returns the JSONObject that has some data from the object as a JSONObject!

Here is the method I’d really like to call,

public JSONObject(java.lang.Object object, java.lang.String[] names)

Where:

object – An object that has fields that should be used to make a JSONObject.
names – An array of strings, the names of the fields to be obtained from the object.

However, eclipse isn’t admitting that this specific constructor call is valid, though there’s online documentation for it.

How can I get this to work for me?

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

    You have two choices,

    a. If you want to stick with the standard org.gson libraries, you can write your own

    public static MyObject fromJson(String json)
    public String toJson()
    

    methods for each model object. The implementation of each must use the org.json library to populate the fields of the object, and to build a JSON and from the object’s fields, respectively.

    b. use GSON or jackson that by design will perform object binding. GSON is simpler, jackson is faster.

    https://sites.google.com/site/gson/gson-user-guide

    Really, I did a performance eval of all three, and it went 1. org.json, jackson, and gson, with gson being ~10x slower. It’s not really fair to compare org.json however because it doesn’t include object binding code.

    If you have a simple flat model object with direct mapping to JSON, they are both brain dead simple. If you want custom mappings or have complex structures, you will need to read the docs and write some custom serialization / deserialization code.

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

Sidebar

Related Questions

I am trying create a data.frame from which to create a graph. I have
I'm trying create a method that returns the sum of all values in an
I'm trying create an immutable object and initialise it from xml config file in
I am trying create system in which I can login from php and then
I am trying create a WCF Data Services ServiceOperation that does grouping on the
I am trying create a trending system that displays which keywords are trending by
I'm trying create simple application in C++. This application has to read from file
Trying to create an app that does some socket communication (Writing only). I can
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,

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.