I am getting the record last 6 months from the database. Based on the current Date. I am storing into an JSONArray when I am returning it - I am getting Serialization Error, because there is not Getter and setter. My data looks like this -
[
{
"userName": "Sita",
"userEmail": "sita@gmail.com",
"January": 3,
"February": 10,
"March": 1,
"April": 3,
"May": 32,
"June": 31
},
{
"userName": "Gita",
"userEmail": "gita@gmail.com",
"January": 3,
"February": 10,
"March": 1,
"April": 3,
"May": 32,
"June": 31
},
{
"userName": "Ram",
"userEmail": "ram@gmail.com",
"January": 3,
"February": 10,
"March": 1,
"April": 3,
"May": 32,
"June": 31
}
]
Now the question is --> Month Name can come dynamiclly. How I can I set this into my setter Getter Method, and call it from ServiceImp --> controller
I can't do like this -
@Data
@NoArgsConstructor
@AllArgsConstructor
private String userName;
private String userName;
private String January;
private String February;
private String March;
private String April;
private String May;
private String June;
private String July;
private String August;
private String September;
private String October;
private String November;
private String December;
Its not the good way. I tried with many way. Can you please help me how I can achive this, and Write In a serviceImpl and Controller file. I am new to this spring boot, Any help would be appriciated.
If we keep like this, how do I map it to the specific month in a serviceImp ? Can please provide the code ? How do I map it. Like If I got the JSONObject like this -
for (int i = 0; i < filterUser.length(); i++) {
JSONObject jsb = (JSONObject) filterUser.get(i);
jsb.keySet().forEach(keyStr -> {
// Here Key is January, and jsb.get(keyStr) -> January data
// How can I set the setter and getter here ?
// });
// filteredTotalFeedbackData.put(i, jsb);
}