0
Hello
I have this method in my controller:
@GetMapping(value="/{id}/perfil", produces = MediaType.APPLICATION_JSON_VALUE)
public String carregarPerfilUsuario(@PathVariable("id") Long id, HttpServletResponse response) throws IOException {
obj.put("usuario", ur.findWhereId(id));
obj.put("postagem", pr.findAllWhereUserId(id));
return gson.toJson(obj);
}
I’m using gson
to turn an object into json and JsonOBJECT
to create an obj that will be returned at the end:
private static final Gson gson = new Gson();
private static final JSONObject obj = new JSONObject();
however do not know why while converting my data it inserts unwanted attributes into my api:
Map and Myarraylist, I wish I didn’t see those attributes when I convert, like I do?
The result I’m looking for is similar to the image, I just wish I didn’t have these attributes I commented in bold in the question.
See if using GSON’s own Jsonobject instead of Jsonobject solves your problem.
– StatelessDev
You’re using the right class (
JsonObject
)? I tried to reproduce here but I couldn’t find the methodput
in that class :(– igventurelli