Sumit Kumar
Sumit Kumar

Reputation: 584

Any shortcut or plugin to generate constructor with parameter JSONObject as following code

class Person {
    String name;
    String age;

    public Person(JSONObject obj) throws exception{
        this.name = obj.getString("name");
        this.age = obj.getString("age");
    }
}

Those are few attributes but I have a huge list of other attributes. I know shortcut about how to create constructer, getter, setter. But I don't know a shortcut to create the above code automatically.

Upvotes: 0

Views: 363

Answers (3)

ITSGuru
ITSGuru

Reputation: 194

You can generate using right click.

OR

Key shortcut = Alt + Insert

Upvotes: 0

nifCody
nifCody

Reputation: 2444

There is more way you have to create getters and setters.

  1. Go to your class you want to add getter and setter

  2. Then press key is Alt + Insert or Right Click and choose generate

  3. then you will able to see a menu and click generate setters and getter or constructor on your desire

  4. after that choose the variables with Ctrl or Shift

Hope I answer your question.

Upvotes: 0

Dishonered
Dishonered

Reputation: 8841

Use google's gson library gson

Like this

Gson gson = new Gson();
Person person = gson.fromJson(jsonInString, Person.class);

Upvotes: 1

Related Questions