Issue
I have a DTO like below:
@Getter
@Setter
@AllArgsConstructor
public class LightRoundResponse {
private String round;
private JSONObject fields;
}
I am able to store and fetch the JSON Object from the DB. After setting DTO's fields attribute with the ResultSet's fields, I am able to see the JSONObject containing the correct data while debugging.
However the response which I get is:
{
"round": "A Round",
"fields": {
"empty": false
}
}
fields object is incorrect, I think since it's a JSONObject it could be an issue but I am not sure.
How can I get the correct response and not "empty": false
Solution
Jackson does not know how to serialize JSONObject
class. The expected way to do that is to actually use Map<String, Object>
:
@Getter
@Setter
@AllArgsConstructor
public class LightRoundResponse {
private String round;
private Map<String, Object> fields;
}
Answered By - lkatiforis
Answer Checked By - Clifford M. (JavaFixing Volunteer)