Reputation: 584
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
Reputation: 2444
There is more way you have to create getters and setters.
Go to your class you want to add getter and setter
Then press key is Alt + Insert
or Right Click and choose generate
then you will able to see a menu and click generate setters and getter or constructor on your desire
after that choose the variables with Ctrl
or Shift
Hope I answer your question.
Upvotes: 0
Reputation: 8841
Use google's gson library gson
Like this
Gson gson = new Gson();
Person person = gson.fromJson(jsonInString, Person.class);
Upvotes: 1