I have a json structure that looks something like this
{"overallobject
"object1": {
},
"object2": {
"field1": null,
"listObject": [{
"field2": null,
"field3": null,
}]
}
}
My model class of this json object looks like this:
public class Overallobject {
public static class Object1{
}
public static class Object2{
private String field1;
public List<ListObject> listObject = new ArrayList<ListObject>();
}
public static class ListObject{
public String field2;
public String field3;
}
}
I have a model class that turns the above json into POJO and a service class that turns the model class into a string with some additions.
In my service class, I can execute the code perfectly fine like this:
import Overallobject;
public class Service() {
Overallobject overallobject = new Overallobject();
List<ListObject> listObject = new ArrayList<ListObject>;
overallobject.getList.add(listObject); // this lets me add objects to the list array so its not empty when instantiated
}
However I was wondering if I could instantiate the list objects within the model class instead of the service class. I've tried to create the list object inside the model class but I can't seem to add it and I get the error. If i don't try to instantiate the list object, listObject returns an empty array [].
class member declared outside of a class java