I\'m having trouble reading a JSON file into a POJO. Let me give you a snippet of what my JSON file entails:
{
\"Speidy\": {
\"factionId\": \"2\",
You're listing what appears to be a name, which you possibly meant to represent a value, as a property name for an object. Instead, include the name inside the JSON string and assign it a property name that will actually appear as a private variable (with getters and setters) in your Java Node class.
With this in place, you should then be able to deserialize your JSON back into an object. Also, since on the server-side you're representing the Node collection as a List, I converted the JSON to an array that contains two objects. In JavaScript, you'd access them as node[0].name
and node[1].name
, which would equate to nodes.get(0).getName()
on the server-side:
[
{
"name" : "Speidy",
"factionId": "2",
"role": "ADMIN",
"title": "",
"power": 9.692296666666667,
"powerBoost": 0.0,
"lastPowerUpdateTime": 1337023306922,
"lastLoginTime": 1337023306922,
"chatMode": "PUBLIC"
},
{
"name" : "ShadowSlayer272",
"factionId": "2",
"role": "NORMAL",
"title": "",
"power": 0.8673466666666667,
"powerBoost": 0.0,
"lastPowerUpdateTime": 1336945426926,
"lastLoginTime": 1336945426926,
"chatMode": "PUBLIC"
}
]
public class Node {
private String name = "";
private int factionId = 0;
private String role = "";
private String title = "";
private double power = 0.0;
private double powerBoost = 0.0;
private int lastPowerUpdateTime = 0;
private int lastLoginTime = 0;
private String chatMode = "";
}
With that said, if you really do need to use the name as a property name, then consider deserializing the JSON to a HashMap instead of a List. Lists generally map to JSON arrays, whereas Maps generally are better suited towards representing several JSON objects inside a parent object.