question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ParsingException in Response#getArray()

See original GitHub issue

General Troubleshooting

  • I have checked for similar issues.
  • I have updated to the latest JDA version
  • I have checked the branches or the maintainers’ PRs for upcoming bug fixes.

Bug Report

When creating a RestAction to retrieve guild data (e.g. all channels) the RestActions fails with a ParsingException.

I tried to ask on the Discord server but either no one could help me or my question got lost between other questions (twice). What I’m trying to do is to save all the data from a guild to local files (messages, attachments, metadata …). This should be the raw JSON to avoid having to manually go through everything and to ensure that no data gets lost.

Expected Behavior

The RestAction should have successfully returned a DataArray (i think).

Code Example or Reproduction Steps

Route.CompiledRoute route = Route.Guilds.GET_CHANNELS.compile(/*valid guild id*/);
DataArray data = new RestActionImpl<DataArray>(jda, route, (response, dataArrayRequest) -> response.getArray()).complete();

Code for JDABuilder or DefaultShardManagerBuilder Used

JDABuilder.createDefault(token)
    .setMemberCachePolicy(MemberCachePolicy.NONE);
    .setStatus(OnlineStatus.IDLE);
    .build();

Exception or Error

StackTrace
java.lang.IllegalStateException: An error occurred while parsing the response for a RestAction
    net.dv8tion.jda.api.requests.Response.parseBody(Response.java:220)
    net.dv8tion.jda.api.requests.Response.parseBody(Response.java:182)
    net.dv8tion.jda.api.requests.Response.get(Response.java:124)
    net.dv8tion.jda.api.requests.Response.getObject(Response.java:105)
    de.eldritch.discord.turtlecrawler.task.tasks.GuildTask.lambda$handleMetadata$0(GuildTask.java:120)
    net.dv8tion.jda.internal.requests.RestActionImpl.handleSuccess(RestActionImpl.java:278)
    net.dv8tion.jda.internal.requests.RestActionImpl.handleResponse(RestActionImpl.java:268)
    net.dv8tion.jda.api.requests.Request.handleResponse(Request.java:259)
    net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:237)
    net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:141)
    net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:124)
    net.dv8tion.jda.internal.requests.ratelimit.BotRateLimiter$Bucket.run(BotRateLimiter.java:478)
    java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    java.base/java.lang.Thread.run(Thread.java:833)

// caused by:

net.dv8tion.jda.api.exceptions.ParsingException: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.HashMap<java.lang.Object,java.lang.Object>` out of START_ARRAY token at [Source: (BufferedReader); line: 1, column: 1]
    net.dv8tion.jda.api.utils.data.DataObject.fromJson(DataObject.java:184)
    net.dv8tion.jda.api.requests.Response.parseBody(Response.java:204)
    net.dv8tion.jda.api.requests.Response.parseBody(Response.java:182)
    net.dv8tion.jda.api.requests.Response.get(Response.java:124)
    net.dv8tion.jda.api.requests.Response.getObject(Response.java:105)
    de.eldritch.discord.turtlecrawler.task.tasks.GuildTask.lambda$handleMetadata$0(GuildTask.java:120)
    net.dv8tion.jda.internal.requests.RestActionImpl.handleSuccess(RestActionImpl.java:278)
    net.dv8tion.jda.internal.requests.RestActionImpl.handleResponse(RestActionImpl.java:268)
    net.dv8tion.jda.api.requests.Request.handleResponse(Request.java:259)
    net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:237)
    net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:141)
    net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:124)
    net.dv8tion.jda.internal.requests.ratelimit.BotRateLimiter$Bucket.run(BotRateLimiter.java:478)
    java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    java.base/java.lang.Thread.run(Thread.java:833)

// caused by:

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.HashMap<java.lang.Object,java.lang.Object>` out of START_ARRAY token at [Source: (BufferedReader); line: 1, column: 1]
    com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
    com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1442)
    com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1216)
    com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1126)
    com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromEmpty(StdDeserializer.java:639)
    com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:360)
    com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:29)
    com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4202)
    com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3234)
    net.dv8tion.jda.api.utils.data.DataObject.fromJson(DataObject.java:179)
    net.dv8tion.jda.api.requests.Response.parseBody(Response.java:204)
    net.dv8tion.jda.api.requests.Response.parseBody(Response.java:182)
    net.dv8tion.jda.api.requests.Response.get(Response.java:124)
    net.dv8tion.jda.api.requests.Response.getObject(Response.java:105)
    de.eldritch.discord.turtlecrawler.task.tasks.GuildTask.lambda$handleMetadata$0(GuildTask.java:120)
    net.dv8tion.jda.internal.requests.RestActionImpl.handleSuccess(RestActionImpl.java:278)
    net.dv8tion.jda.internal.requests.RestActionImpl.handleResponse(RestActionImpl.java:268)
    net.dv8tion.jda.api.requests.Request.handleResponse(Request.java:259)
    net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:237)
    net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:141)
    net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:124)
    net.dv8tion.jda.internal.requests.ratelimit.BotRateLimiter$Bucket.run(BotRateLimiter.java:478)
    java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    java.base/java.lang.Thread.run(Thread.java:833)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
MinnDevelopmentcommented, Mar 27, 2022

That body should parse just fine with the code you have provided in the issue. If you can make a proper example with a failure case and an example body which fails to parse, please open a new issue with the consistent reproduction steps. Your code in the initial issue description works fine, and the body you have shown also parses into an array correctly.

Make sure that you use getArray() for Route.Guilds.GET_CHANNELS and getObject() for Route.Guilds.GET_GUILD. That works fine in all my testing.

0reactions
TurtleExceptioncommented, Mar 27, 2022

Sorry again, I uncommented the wrong line :c removed

Read more comments on GitHub >

github_iconTop Results From Across the Web

com.grack.nanojson.JsonParser$JsonParserContext.from ...
JsonObject parentObject = JsonParser.object().from(in); JsonArray channelsArray ... e) { throw new ParsingException("Could not parse json response", ...
Read more >
JDA/GuildImpl.java at master · DV8FromTheWorld/JDA - GitHub
response.getArray().stream(DataArray::getObject). ... DataArray arr = response.getArray(); ... catch (ParsingException | ClassCastException ex).
Read more >
net.dv8tion.jda.api.entities.User Java Examples
addField(languageContext.get(leaderboardKey), lb.stream() ... getEntityBuilder(); final DataArray array = response.getArray(); final List<User> users = new ...
Read more >
Java JsonParser类代码示例- Java编程经验-OGeek|极客世界-中国 ...
clientId() + "&limit=10"; String response = dl.download(url); try { JsonArray ... e) { throw new ParsingException("Could not parse json response", e); } }....
Read more >
https://git.lain.faith/be-gay-do-crimes/NewPipeExt...
getRequest(), response. ... ParsingException { + public void testGetInvidiousIdfromUrl() throws ParsingException { assertEquals("TglNG-yjabU", linkHandler.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found