I'm a front end developer who is brand new to backend development. My task is to model json in a Java object. It's just some mock data for now that my controller returns.
{
"data":{
"objectId":25,
"columnName":[
"myCategory",
"myCategoryId"
],
"columnValues":[
[
"Category One",
1
],
[
"Category Two",
2
],
[
"Category Three",
3
],
[
"Category Four",
4
],
[
"Category Five",
5
]
]
}
}
And here's my attempt. The controller returns this json correctly. But isn't this too simple? What I believe should be done is extrapolate the columnName and columnValues arrays into separate classes but I'm not sure how.
package com.category;
import java.util.List;
public class MyObjectData {
private int objectId;
private List columnName;
private List columnValues;
public int getObjectId() {
return objectId;
}
public void setObjectId(int objectId) {
this.objectId = objectId;
}
public List getColumnName() {
return columnName;
}
public void setColumnName(List colName) {
this.columnName = colName;
}
public List getColumnValues() {
return columnValues;
}
public void setValues(List values) {
this.columnValues = values;
}
}
Regarding the columnNames and columnValues, I feel like I should be doing something like this in the model instead:
private List<ColumnNames> columnNames;
private List<ColumnValues> columnValues;
public List<ColumnNames> getColumnNames() {
return columnNames;
}
public void setColumnNames(List<ColumnNames> columnNames) {
this.columnNames = columnNames;
}
public List<ColumnValues> getColumnValues() {
return columnValues;
}
public void setColumnValues(List<ColumnValues> columnValues) {
this.columnValues = columnValues;
}
And then I'd have two separate classes for them like this:
package com.category;
import java.util.List;
public class ColumnName {
private String columnName;
public String getColumnName() {
return columnName;
}
public void setColumnName(String columnName) {
this.columnName = columnName;
}
}
package com.category;
import java.util.List;
public class ColumnValue {
private String columnValue;
private int columnValueId;
public String getColumnValue() {
return columnValue;
}
public void setColumnValue(String columnValue) {
this.columnValue = columnValue;
}
public String getColumnValueId() {
return columnValueId;
}
public void setColumnValueId(int columnValueId) {
this.columnValueId = columnValueId;
}
}
I feel like I have all the right pieces but just not sure if this is a better approach than my initial attempt...which works. Just looking for input. Thanks in advance.