I'm working on a mobile application with APIs endpoints returning JSON data and i do a lot of JSON parsing for displaying different types of data in my application.
For a long time i was using Getter Setter with constructor in my java object classes to handle data but recently by colleague told me a bit different and easy approach for handling this exact data. The two different dataObject classes are
The way I was handling my data manipulation
public class MyObject {
String _string1, _string2;
List<String> _stringsList;
public MyObject(String _string1, String _string2, List<String> _stringsList) {
this._string1 = _string1;
this._string2 = _string2;
this._stringsList = _stringsList;
}
public String getString1() {
return _string1;
}
public String getString2() {
return _string2;
}
public List<PostO> getStringList() {
return _stringsList;
}
}
The way my colleague suggested
public class MyObject {
public String _string1, _string2;
public List<String> _stringsList;
public MyObject() { }
}
And the app works fine with both methods. and the second way is short and easy to make edits. But whats the difference between these two? Is there any technical shortcoming in the second method or something? I really need to know before converting my classes to this new method.
I started using GSON with second method, if it matters.