I am reading table from postgreSQL DB and populating all columns and its values in a json object.
One of the column in postgre is of type json. So the output has lot of escape characters. like below for key dummykeyname.
{
"XY": "900144",
"id": 1,
"date": 1556167980000,
"type": "XX50",
"dummykeyname": {
"type": "json",
"value": "{\"XXXX\": 14445.0, \"YYYY\": 94253.0}"
}
}
I want the output to look like
"value": "{"XXXX": 14445.0, "YYYY": 94253.0}"
Code i used is
JSONArray entities = new JSONArray();
var rm = (RowMapper<?>) (ResultSet result, int rowNum) -> {
while (result.next()) {
JSONObject entity = new JSONObject();
ResultSetMetaData metadata = result.getMetaData();
int columnCount = metadata.getColumnCount() + 1;
IntStream.range(1, columnCount).forEach(nbr -> {
try {
entity.put(result.getMetaData().getColumnName(nbr), result.getObject(nbr));
} catch (SQLException e) {
LOGGER.error(e.getMessage());
}
});
entities.add(entity);
}
return entities;
};
Library used:
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
Please guide me where am i going wrong.