I'm facing a weird problem with JSON serialization. I've JPA objects which I'm using annotation #JsonProperty to serialize & deserialize objects to JSON data.
Query. java
#Entity
#XmlRootElement
public class Query {
#Id
#GeneratedValue
private int queryId;
#ManyToOne
#JoinColumn(name="institution_id")
#JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="institutionId")
private InstitutionDetails institution;
#ManyToOne
#JoinColumn(name="department_id")
#JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="deptId")
private Department department;
#ManyToOne
#JoinColumn(name="topic_id")
#JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="topicId")
private Topic topic;
#ManyToOne
#JoinColumn(name="raised_by_user_id")
#JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property="email")
private User raisedByUser;
#Lob
private String query;
#Column(name="query_date")
private Date queryDate;
#Column(name="query_answered")
private boolean queryAnswered;
#OneToMany(cascade=CascadeType.ALL, mappedBy="query", fetch=FetchType.LAZY)
private Set<Response> responses;
#JsonProperty
public int getQueryId() {
return queryId;
}
public void setQueryId(int queryId) {
this.queryId = queryId;
}
#JsonProperty
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
#JsonProperty
public Topic getTopic() {
return topic;
}
public void setTopic(Topic topic) {
this.topic = topic;
}
#JsonProperty
public User getRaisedByUser() {
return raisedByUser;
}
public void setRaisedByUser(User raisedByUser) {
this.raisedByUser = raisedByUser;
}
#JsonProperty
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
#JsonProperty
public Date getQueryDate() {
return queryDate;
}
public void setQueryDate(Date queryDate) {
this.queryDate = queryDate;
}
#JsonProperty
public boolean isQueryAnswered() {
return queryAnswered;
}
public void setQueryAnswered(boolean queryAnswered) {
this.queryAnswered = queryAnswered;
}
#JsonProperty
public Set<Response> getResponses() {
return responses;
}
public void setResponses(Set<Response> responses) {
this.responses = responses;
}
#JsonProperty
public InstitutionDetails getInstitution() {
return institution;
}
public void setInstitution(InstitutionDetails institution) {
this.institution = institution;
}
}
Department.java
#Entity
#XmlRootElement
public class Department {
#Id
#GeneratedValue
private int deptId;
#Column(name="department_name", length=100)
private String departmentName;
#OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
#JoinColumn(name="department_id")
private Set<Topic> topic;
#OneToMany(cascade=CascadeType.ALL, mappedBy="department", fetch=FetchType.LAZY)
private Set<Query> queries;
#JsonProperty
public int getDeptId() {
return deptId;
}
public void setDeptId(int deptId) {
this.deptId = deptId;
}
#JsonProperty
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
#JsonProperty
public Set<Topic> getTopic() {
return topic;
}
public void setTopic(Set<Topic> topic) {
this.topic = topic;
}
#JsonIgnore
public Set<Query> getQueries() {
return queries;
}
public void setQueries(Set<Query> queries) {
this.queries = queries;
}
}
QueryController.java
#GET
#Path("/getAllAnsweredQueries/{institutionId}/{departmentId}/{topicId}")
#Produces({MediaType.APPLICATION_JSON})
public List<Query> getAllAnsweredQueries(#PathParam("institutionId") int institutionId, #PathParam("departmentId") int departmentId, #PathParam("topicId") int topicId) {
return m_queryService.getAllAnsweredQueries(institutionId, departmentId, topicId);
}
The above method returns a List
But the Serialized JSON object doesn't contain the entire child object details from the 2nd item in the list. The 1st JSON object has everything correctly. Then 2nd JSON object in the list is missing some object details:
Output JSON
[
{
"queryId": 7,
"institution": {
"institutionId": 1004,
"instituionName": "A College"
},
"department": {
"deptId": 1,
"departmentName": "Anatomy",
"topic": [
{
"topicId": 1003,
"topicName": "Nervous System"
},
{
"topicId": 1002,
"topicName": "Muscular System"
},
{
"topicId": 1006,
"topicName": "Vascular System"
},
{
"topicId": 1005,
"topicName": "Cells & Tissues"
},
{
"topicId": 1004,
"topicName": "Circulatory Sytem"
},
{
"topicId": 1001,
"topicName": "Skeletal System"
}
]
},
"topic": {
"topicId": 1001,
"topicName": "Skeletal System"
},
"raisedByUser": {
"email": "abcd#gmail.com",
"userName": "User A",
"userType": {
"userTypeId": 10001,
"userType": "Student"
},
"institutionDetails": 1004,
"registeredDate": 1439136336000,
"mobileNumber": "12346578"
},
"query": "What causes bone damage ?",
"queryDate": 1439139172000,
"queryAnswered": false,
"responses": []
},
{
"queryId": 6,
"institution": 1004,
"department": 1,
"topic": {
"topicId": 1002,
"topicName": "Muscular System"
},
"raisedByUser": "abcd#gmail.com",
"query": "What is the cause of spine disc lapse ?",
"queryDate": 1439137989000,
"queryAnswered": true,
"responses": [
{
"responseId": 2,
"query": {
"queryId": 6,
"institution": 1004,
"department": 1,
"topic": 1002,
"raisedByUser": "abcd#gmail.com",
"query": "What is the cause of spine disc lapse ?",
"queryDate": 1439137989000,
"queryAnswered": true,
"responses": [
{
"responseId": 2,
"query": 6,
"respondedByUser": {
"email": "mnop#gmail.com",
"userName": "User B",
"userType": {
"userTypeId": 10002,
"userType": "Expert"
},
"institutionDetails": 1004,
"registeredDate": 1439136400000,
"mobileNumber": "12346578"
},
"response": "Incorrect seating position",
"responseDate": 1439138916000
}
]
},
"respondedByUser": "mnop#gmail.com",
"response": "Incorrect seating position",
"responseDate": 1439138916000
}
]
}
]
If you notice in the 1st result (queryId: 7), department Object & respondedByUser object will be expanded whereas in the 2nd result (queryId: 6) the objects department & respondedByUser are not expanded. When I debug & see the values before the serialization, the objects are having their respective values properly.
Why is it happening so ? Am I missing something ?
That is because you are asking Jackson to use Object Ids, with annotation #JsonIdentityInfo. So after initially serializing objects completely, further references refer to the object id.
Related
I have just started using Spring boot and I am using the default repository api to retrieve db data as json.
I have added a #ManyToOne relation to my Song and Artist Entity.
But now i am not getting the Artist object in my json response from the server and its not really clear to me, how I can include it without missing out on the pagination functions from the PagingAndSorting repository.
I am using the spring-data-rest-jpa.
My response now looks like:
"_embedded": {
"songs": [
{
"id": 1,
"title": "SongTitle",
"genre": "Rap",
"length": 500,
"_links": {
"self": {
"href": "http://localhost:8080/api/songs/1"
},
"song": {
"href": "http://localhost:8080/api/songs/1"
},
"artist": {
"href": "http://localhost:8080/api/songs/1/artist"
}
}
}
]
},
"_links": {
"first": {
"href": "http://localhost:8080/api/songs?page=0&size=1"
},
"self": {
"href": "http://localhost:8080/api/songs?size=1"
},
"next": {
"href": "http://localhost:8080/api/songs?page=1&size=1"
},
"last": {
"href": "http://localhost:8080/api/songs?page=19&size=1"
},
"profile": {
"href": "http://localhost:8080/api/profile/songs"
}
},
"page": {
"size": 1,
"totalElements": 20,
"totalPages": 20,
"number": 0
}
}
But I want it rather to be like this:
"_embedded": {
"songs": [
{
"id": 1,
"title": "SongTitle",
"genre": "Rap",
"length": 500,
"artist": {
"id": 1,
"name": "Artistname"
}
"_links": {
"self": {
"href": "http://localhost:8080/api/songs/1"
},
"song": {
"href": "http://localhost:8080/api/songs/1"
},
"artist": {
"href": "http://localhost:8080/api/songs/1/artist"
}
}
}
]
},
"_links": {
"first": {
"href": "http://localhost:8080/api/songs?page=0&size=1"
},
"self": {
"href": "http://localhost:8080/api/songs?size=1"
},
"next": {
"href": "http://localhost:8080/api/songs?page=1&size=1"
},
"last": {
"href": "http://localhost:8080/api/songs?page=19&size=1"
},
"profile": {
"href": "http://localhost:8080/api/profile/songs"
}
},
"page": {
"size": 1,
"totalElements": 20,
"totalPages": 20,
"number": 0
}
}
Song.java
#Getter
#Setter
#Entity
#Table(name = "song")
public class Song {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id", nullable = false, unique = true)
private Long id;
#NotNull
#NotBlank(message = "The song has to have a title")
private String title;
#NotNull
#NotBlank(message = "The song has to have a genre")
private String genre;
#NotNull
#Min(value = 1, message = "The song has to have a song length in seconds")
private int length;
#ManyToOne(cascade = CascadeType.ALL)
#JoinColumn(name = "artist_id", referencedColumnName = "id")
private Artist artist;
/* #Version
private long version;*/
public Song() {
}
public Song(String title, Artist artist, String genre, int length) {
this.title = title;
this.artist = artist;
this.genre = genre;
this.length = length;
}
public void setArtist(Artist artist) {
this.artist = artist;
}
public Artist getArtist() {
return artist;
}
}
Artist.java
#Getter
#Setter
#Entity
#Table(name = "artist")
public class Artist {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "id", nullable = false)
private Long id;
#NotNull
#NotBlank(message = "The artist has to have a name")
private String name;
#JsonIgnore
#OneToMany(mappedBy = "artist")
private List<Song> songs;
public Artist() {
}
public Artist(String name) {
this.name = name;
}
For the sake of testing I wrote a method in my SongController:
#GetMapping
List<Song> getSongs() {
return songRepository.findAll();
}
The result includes the Artist object, but won't have any pagination to it. How could I include it?
Json Result:
[
{
"id": 1,
"title": "SongTitle",
"genre": "Rap",
"length": 500,
"artist": {
"id": 1,
"name": "ArtistName"
}
}
]
After all your useful suggestions I have found an answer:
I have changed the return type of my Method in my controller to Page and made use of the PageRequest Class which looks like this:
#GetMapping
public Page<Song> getSongs(#RequestParam(defaultValue = "0") int page, #RequestParam(defaultValue = "5") int size) {
PageRequest pr = PageRequest.of(page, size);
return songRepository.findAll(pr);
}
Also used some defaultvalues to avoid some exceptions ;)
Use either #JsonIdentityInfo or #JsonIgnore and remove #JsonBackReference. Here is the example with #JsonIgnore
public class Artist {
public Long id;
public String name;
public List<Song> songs;
}
public class Song {
public Long id;
public String title;
public String genre;
public int length;
#JsonIgnore
public Artist artist;
}
#JsonManagedReference or #JsonBackReference won't help in this case (read more on https://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion):
(...) we can use the #JsonIgnore annotation to simply ignore one of the sides of the relationship, thus breaking the chain. [my addition: the chain of recurrent calls]
Here is the example with #JsonIdentityInfo:
#JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
public class Artist { ... }
#JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id")
public class Song { ... }
I have 2 MongoDB collections, named "product" and "file_data", "file_data" contains images of a single product in "product" by productId.
Entity Product
public class Product {
private String id;
private String link;
private String externalId;
private String createdBy;
private Date createdStamp;
}
Entity FileData
public class FileData {
private String id;
private Date date;
private String createdBy;
private String productId;
private String fileName;
How can I retrieve product information as JSON like this:
"data": {
"id": "3793",
"link": "https://example.com/abc.jpg,
"externalId": "562282907969",
"createdBy": "123456#gmail.com",
"createdStamp": 1624330935051,
"images": {
"id": "zxc",
"date": "1624330935051",
"createdBy": "123456#gmail.com",
"productId": "3793",
"fileName": "abc.jpg",
},
{
"id": "zxc",
"date": "1624330935051",
"createdBy": "123456#gmail.com",
"productId": "3793",
"fileName": "abc.jpg",
},
}
Here is my code:
#GET
#Produces(MediaType.APPLICATION_JSON)
public Response getProducts() {
try {
HashMap<String, Object> result = new HashMap<>();
JSONArray list = new JSONArray();
List<Product> products = getProductManager().getProductsByPartyId(getAuth().getString("partyGroupId"));
if (null != products && products.size() > 0) {
products.forEach(product -> {
list.put(getFileDataManager().getFileDataList(product.getId(), "PRODUCT"));
});
result.put("data", products);
result.put("status", 1);
}
return result(result);
} catch (Exception ex) {
ex.printStackTrace();
return Response.status(400).entity(getErrorMessage(ex.getMessage())).build();
}
}
It only shows
"data": {
"id": "3793",
"link": "https://example.com/abc.jpg,
"externalId": "562282907969",
"createdBy": "123456#gmail.com",
"createdStamp": 1624330935051,
}
Please help me. Thank you
So I have a JSON string of countries like this:
{
"details": [
{
"country_id": "1",
"name": "Afghanistan",
"regions": null
},
{
"country_id": "2",
"name": "Albania",
"regions": null
},
{
"country_id": "3",
"name": "Algeria",
"regions": null
},
... and so on
}
Now I want to have a method that tries to convert this into an ArrayList of countries.
public static ArrayList<GFSCountry> get() {
return new Gson().fromJson(countriesJson, new TypeToken<ArrayList<GFSCountry>>(){}.getType());
}
But I get an
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path
As per request, here is my GFSCountry class:
#SerializedName("country_id")
#Expose
private String countryId;
#SerializedName("name")
#Expose
private String name;
#SerializedName("regions")
#Expose
private Object regions;
public String getCountryId() {
return countryId;
}
public void setCountryId(String countryId) {
this.countryId = countryId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Object getRegions() {
return regions;
}
public void setRegions(Object regions) {
this.regions = regions;
}
I know I should adjust something either from the JSON string or the method. Any help?
Since the list is nested in your JSON you will need a small mapping class that contains the list.
Try
static class GFSCountryList {
public List<GFSCountry> details;
}
public static List<GFSCountry> get() {
return new Gson().fromJson(countriesJson, GFSCountryList.class).details;
}
It seems to me that Gson is expecting your json to be like this
[
{
"country_id": "1",
"name": "Afghanistan",
"regions": null
},
{
"country_id": "2",
"name": "Albania",
"regions": null
},
{
"country_id": "3",
"name": "Algeria",
"regions": null
},
... and so on
]
But it encounters an object (marked by { })
Either you have the possibility to change your json format, or you create a class with a "details" attribut as a list to be compatible with the json's format.
I have two entities responsible for fetching data from two different tables and i have created a class to display the combined result of those two entities. I am able to fetch the data using JPA but the output is not in the desired JSON format.
First Entity,
#Entity
#Table(name="basicinfo")
public class Rfx_BasicInfo implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#Column(unique = true)
private String uniqueid;
private String description;
private String uniqueidstatus;
private LocalDateTime startdate;
private LocalDateTime enddate;
private String createdby;
public String getCreatedby() {
return createdby;
}
public Long getId() {
return id;
}
public String getUniqueid() {
return uniqueid;
}
public String getDescription() {
return description;
}
public LocalDateTime getStartdate() {
return startdate;
}
public LocalDateTime getEnddate() {
return enddate;
}
public String getUniqueidstatus() {
return uniqueidstatus;
}
}
and the Second one,
#Entity
#Table(name="supplierinvite")
public class Rfx_SupplierInvite {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String externalstatus;
private String uniqueid;
public String getExternalstatus() {
return externalstatus;
}
public String getUniqueid() {
return uniqueid;
}
}
These two are the repositories for the entities i created.
#Repository("rfxBasicInfoRepository")
public interface Rfx_BasicInfoRepository extends JpaRepository<Rfx_BasicInfo,Long> {
#Query(value="SELECT u from Rfx_BasicInfo u where u.createdby = :createdby")
List<Rfx_BasicInfo> findReportByLoginId(#Param("createdby") String createdby);
}
#Repository("rfxSupplierInviteRepository")
public interface Rfx_SupplierInviteRepository extends JpaRepository<Rfx_SupplierInvite,Long> {
#Query(value="SELECT u.uniqueid, u.externalstatus, count(u.externalstatus) from Rfx_SupplierInvite u where u.uniqueid in (:uniqueid) group by u.uniqueid,u.externalstatus order by u.uniqueid, u.externalstatus")
List<Rfx_SupplierInvite> findReportByUniqueId(#Param("uniqueid") String uniqueid);
}
In the first repository i'm fetching the data based on the "createdby" field and in the second one i'm fetching the data based on "uniqueid" field. This "uniqueid" field is common between the two tables. As of now, i have tried to fetch the results separately and merge them into one using a class. I didn't use any JPA mapping and Joins because i'm not sure how to use it here properly.
public class Rfx_Model {
private List<Rfx_BasicInfo> rfx_basicInfoList;
private List<Rfx_SupplierInvite> rfx_supplierInviteList;
public Rfx_Model(List<Rfx_BasicInfo> rfx_basicInfoList, List<Rfx_SupplierInvite> rfx_supplierInviteList) {
this.rfx_basicInfoList = rfx_basicInfoList;
this.rfx_supplierInviteList = rfx_supplierInviteList;
}
public List<Rfx_BasicInfo> getRfx_basicInfoList() {
return rfx_basicInfoList;
}
public List<Rfx_SupplierInvite> getRfx_supplierInviteList() {
return rfx_supplierInviteList;
}
}
This is my controller,
#RequestMapping(value="/buyerLandingReport/{LoginID}",method = RequestMethod.GET)
public ResponseEntity<Object> buyerLandingReport(#PathVariable("LoginID") String LoginID) {
try{
List<Rfx_BasicInfo> list1 = rfxBasicInfoRepository.findReportByLoginId(LoginID);
List<Rfx_SupplierInvite> list2 = rfxSupplierInviteRepository.findReportByUniqueId(list1.get(0).getUniqueid());
return new ResponseEntity(new Rfx_Model(list1,list2),HttpStatus.OK);
}
catch (Exception ex){
throw ex;
}
}
Below is the current JSON ouput,
{
"Rfx_BasicInfo": [
{
"id": 1,
"uniqueid": "RA001",
"description": "sbhdjajd",
"uniqueidstatus": "ajsd",
"startdate": "2018-05-04T12:00:00",
"enddate": "2018-05-04T12:00:00",
"createdby": "RIL01"
},
{
"id": 2,
"uniqueid": "RA001",
"description": "kasksj",
"uniqueidstatus": "sjkds",
"startdate": "2018-05-04T12:00:00",
"enddate": "2018-05-04T12:00:00",
"createdby": "RIL01"
},
{
"id": 3,
"uniqueid": "RA002",
"description": "asjhkdj",
"uniqueidstatus": "asjhd",
"startdate": "2018-05-04T12:00:00",
"enddate": "2018-05-04T12:00:00",
"createdby": "RIL01"
}
],
"Rfx_SupplierInvite": [
[
"uniqueid": "RA001",
"externalstatus":"AC",
"count": 1
],
[
"uniqueid": "RA001",
"externalstatus": "IN",
"count": 2
]
]
}
and the desired JSON ouput format is this one,
[
{
"Rfx_BasicInfo": {
"id": 1,
"uniqueid": "RA001",
"description": "Auction for taking bid for work on route Tirora Gondiya",
"uniqueidstatus": "PB",
"startdate": "2018-05-04T12:00:00",
"enddate": "2018-05-04T14:00:00",
"createdby": "RIL03"
},
"Rfx_Supplier" : [
{
"uniqueid": "RA001",
"externalstatus": "AC",
"count": 1
},
{
"uniqueid": "RA001",
"externalstatus": "IN",
"count": 2
}
]
},
{
"Rfx_BasicInfo": {
"id": 2,
"uniqueid": "RA002",
"description": "Auction for taking bid for work on route Gondiya - Amgaon",
"uniqueidstatus": "DR",
"startdate": "2018-05-04T14:00:00",
"enddate": "2018-05-04T16:00:00",
"createdby": "RIL03"
},
"Rfx_Supplier" : [
{
"uniqueid": "RA002",
"ExternalStatus": "AC",
"count": 1
},
{
"uniqueid": "RA002",
"ExternalStatus": "IN",
"count": 2
}
]
}
]
I'd really appreciate any suggestions to help me figure out the solution for this.
You really need the ResponseEntity ? If not, the common way is:
#RestController
public class MyController {
#RequestMapping(value="/buyerLandingReport/{LoginID}")
public Rfx_Model buyerLandingReport(#PathVariable("LoginID") String LoginID) {
try{
List<Rfx_BasicInfo> list1 = rfxBasicInfoRepository.findReportByLoginId(LoginID);
List<Rfx_SupplierInvite> list2 = rfxSupplierInviteRepository.findReportByUniqueId(list1.get(0).getUniqueid());
return new Rfx_Model(list1,list2);
}
catch (Exception ex){
throw ex;
}
}
Change your Controller as
#RequestMapping(value="/buyerLandingReport/{LoginID}",method = RequestMethod.GET)
public ResponseEntity<Object> buyerLandingReport(#PathVariable("LoginID") String LoginID) {
try{
List<Rfx_BasicInfo> list1 = rfxBasicInfoRepository.findReportByLoginId(LoginID);
List<Rfx_SupplierInvite> list2 = rfxSupplierInviteRepository.findReportByUniqueId(list1.get(0).getUniqueid());
List<Rfx_Model> body = Arrays.asList(new Rfx_Model(list1, list2);
return new ResponseEntity(body), HttpStatus.OK);
}
catch (Exception ex){
throw ex;
}
}
You need to return a list (or array) to get a json array response.
Getting straight to it...
I have a method that returns a string (see example string below) - essentially, I make a HTTP GET Request to a URL and the response is the string below...
{
"total": 30,
"rows": [
{
"id": 1,
"parent": "parentA",
"children": "childB, childC, childD"
},
{
"id": 2,
"parent": "parentE",
"children": "childF, childG, childH"
},
{
"id": 3,
"parent": "parentI",
"children": "childJ, childK, childL"
},
{
"id": 4,
"parent": "parentM",
"children": "childN, childO"
},
{
"id": 5,
"parent": "parentP",
"children": "childQ, childR, childS, childT"
},
{
"id": 6,
"parent": "parentU",
"children": "childV, childW, childX"
},
{
"id": 7,
"parent": "parentY",
"children": "childZ"
}
]
}
I then assign this string to a variable, then map it to my model...
String strRel = <JSON OBJECT FROM ABOVE>
ObjectMapper mapper = new ObjectMapper();
MyModel obj = mapper.readValue(strRel, MyModel.class);
However, when I run my code, it, unfortunately, returns the following error...
com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.my.models.MyModel out of START_ARRAY token
Ultimately, I know what is causing the error, it's the Array of Objects, "rows"...but I am not sure how to fix it. Obviously, I cannot change the schema of the string/object coming back to me.
Any advice will be greatly appreciated.
UPDATE:
MyModel
public class MyModel {
public MyModel() {}
private int total;
private ModelRows rows;
public int getTotal() { return total; }
public ModelRows getRows() { return rows; }
}
UPDATE:
ModelRows
public class ModelRows {
public ModelRows() {}
private int id;
private String parent;
private String children;
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getParent() { return parent; }
public void setParent(String parent) { this.parent = parent; }
public String getChildren() { return children; }
public void setChildren(String children) { this.children = children; }
}
Made below changes in your MyModel class
public class MyModel {
public MyModel() {}
private int total;
private List<ModelRows> rows;
public int getTotal() { return total; }
public List<ModelRows> getRows() { return rows; }
}