Hi all,
thanks for the prompt replies. I managed to figure out the problem - it was my own mistake, of course.
In brief, I was loading the test data I showed as a Map<String, Object>, then getting the 'timers' map from the map, then trying to load the TestTimer object by parsing the result of toString() as Json... Which results in an unquoted string, which results in a nice little error message.
The bits and pieces were scattered across a class, so I didn't immediately figure it out.
Thanks for showing me that I really should have reduced the issue to its basic components before coming to conclusions. :)
For your enjoyment, below is the distilled version of my scenario, with both the error situation and my solution. The fix is probably not the best available, but it seems to work so far. I'm open to suggestions!
import com.google.gson.reflect.TypeToken;
public class HashTest
{
public static void main(String[] args)
{
String rawData = "{ \"timers\": { \"TestTimer\": { \"interval\": 2, \"remainingTime\": 2, \"repeat\": true, \"event\": \"testevent\", \"eventArguments\": [ \"#tfbottest\" ], \"identifier\": \"TestTimer\", \"isRunning\": false } }}";
Type type = new TypeToken<Map<String, Object>>()
{
}.getType();
Map<String, Object> node = gson.fromJson(rawData, type);
Map<String, Object> timers = (Map<String, Object>) node.get("timers");
Object testTimerObject = timers.get("TestTimer");
boolean fail = true;
String data;
if (fail)
{
data = testTimerObject.toString();
}
else
{
data = gson.toJson(testTimerObject);
}
System.out.println(data);
EventTimer testTimer = gson.fromJson(data, EventTimer.class);
System.out.println(testTimer);
}
}
Thanks for the help.
Sincerely,
Bart