ForgeEssentials

ForgeEssentials

339k Downloads

Mojang API returning JSON that GSON doesn't like

dshadowwolf opened this issue ยท 2 comments

commented

The return from the Mojang API for the 'names' list is a JSON array - this causes an error in the permissions parsing where the following can occur:

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2
        at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:374)
        at com.forgeessentials.util.UserIdentUtils.fetchData(UserIdentUtils.java:72)
        at com.forgeessentials.util.UserIdentUtils.resolveMissingUsername(UserIdentUtils.java:57)
<removed for brevity>

An example is the result of the request using my UUID:

[{"name":"DShadowWolf"}]

I think that the only viable solution is to do a bit of defensive coding around this - if I knew that it was always going to happen I'd just hard-code in a bit that pastes on the expected braces, but there has to be a better solution

commented

Okay, I've looked into this a bit more and the issue might be that you're asking of an Object from GSON for this instead of an Array - looks like the results of the 'names' request is always an array.

commented

I will look into it