I'm struggling to convert a generated from a Primefaces PickList into JSON.
Gson gson = new Gson();
System.out.println(gameTaskHotspots.getTarget().toString());
Type type = new TypeToken<List<GameTaskHotspot>>(){}.getType();
if(gameTaskHotspots.getTarget().size() > 0){
List<GameTaskHotspot> list = gameTaskHotspots.getTarget();
selectedTask.input = gson.toJson(list);
}
System.out.println(selectedTask.input);
It's outputing the bean names in the JSON string, i.e.
The first output is
[co.beek.pano.model.beans.GameTaskHotspot@4697b22e, co.beek.pano.model.beans.GameTaskHotspot@2b7ab42b, co.beek.pano.model.beans.GameTaskHotspot@344f3665]
The Second output is
["co.beek.pano.model.beans.GameTaskHotspot@4697b22e","co.beek.pano.model.beans.GameTaskHotspot@2b7ab42b","co.beek.pano.model.beans.GameTaskHotspot@344f3665"]
Like it's not reading the objects properly. I've tried using the type to give Gson the object, and I get this error:
javax.el.ELException: /views/guide/admin.xhtml @246,147 actionListener="#{GuideViewAdminController.saveSelectedTask()}": java.lang.IllegalArgumentException: Can not set java.lang.String field co.beek.pano.model.beans.GameTaskHotspot.id to java.lang.String
Incidently I use this to convert the Json into a List of Objects and it works great
GameTaskHotspot[] existing = gson.fromJson(type == 0 ? selectedTask.input : selectedTask.output, GameTaskHotspot[].class);