I'm trying to read this json file:
{
"username": "someusername",
"password": "12345678",
"ipAddresses": {
"2015-09-12": "127.0.0.1"
}
}
Using this class to store the info:
private final class SavedPlayer {
private final String username;
private final String password;
private final HashMap<LocalDate, String> ipAddresses;
private SavedPlayer(
String username, String password,
HashMap<LocalDate, String> ipAddresses
) {
this.username = username;
this.password = password;
this.ipAddresses = ipAddresses;
}
}
And this part of the code throws an exception:
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
SavedPlayer savedPlayer = GSON.fromJson(reader, SavedPlayer.class);
This is the thrown exception:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 5 column 17
How can I read this stored HashMap properly?
Edit: it works fine when i use <String, String>
instead of <LocalDate, String>