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.

Exception when deserializing from JSON

See original GitHub issue

When deserializing from JSON, we get the following exception:

Exception in thread "main" java.lang.IllegalArgumentException: Expected integer; got java.lang.Long
	at nonapi.io.github.classgraph.json.JSONDeserializer.jsonBasicValueToObject(JSONDeserializer.java:112)
	at nonapi.io.github.classgraph.json.JSONDeserializer.populateObjectFromJsonObject(JSONDeserializer.java:479)
	at nonapi.io.github.classgraph.json.JSONDeserializer.populateObjectFromJsonObject(JSONDeserializer.java:602)
	at nonapi.io.github.classgraph.json.JSONDeserializer.populateObjectFromJsonObject(JSONDeserializer.java:602)
	at nonapi.io.github.classgraph.json.JSONDeserializer.populateObjectFromJsonObject(JSONDeserializer.java:602)
	at nonapi.io.github.classgraph.json.JSONDeserializer.populateObjectFromJsonObject(JSONDeserializer.java:602)
	at nonapi.io.github.classgraph.json.JSONDeserializer.populateObjectFromJsonObject(JSONDeserializer.java:602)
	at nonapi.io.github.classgraph.json.JSONDeserializer.deserializeObject(JSONDeserializer.java:681)
	at nonapi.io.github.classgraph.json.JSONDeserializer.deserializeObject(JSONDeserializer.java:708)
	at io.github.classgraph.ScanResult.fromJSON(ScanResult.java:1300)
	at classgraphjsonbug.Main.main(Main.java:9)

Even a simple program throws this exception:

package classgraphjsonbug;

import io.github.classgraph.ClassGraph;
import io.github.classgraph.ScanResult;

public class Main {
    public static void main(String[] args) {
        String json = scan();
        ScanResult scanResult = ScanResult.fromJSON(json);
    }

    private static String scan() {
        try (ScanResult scan = new ClassGraph()
                .verbose()
                .enableAllInfo()
                .scan()) {
            return scan.toJSON();
        }
    }
}

We’ve tested this code with the latest version 4.8.80 on the classpath. We have also attached the verbose output:

classgraph-json-bug.txt

Can you tell us what we’re doing wrong?

– Poke

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
lukehutchcommented, Jun 5, 2020

Thanks! Fixed in 4.8.81.

I think you are the first users who tried to use the serialization / deserialization support 😃

0reactions
lukehutchcommented, Jun 9, 2020

You’re also welcome to optimize the serializer and deserializer. I anticipate a 2-10x speedup could be achieved. The code is a bit complex though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Deserialization Exception - Stack Overflow
You're trying to deserialize it into a list of RootObject but in reality the JSON is just a single root object.
Read more >
Serialization Error Handling - Json.NET
The Error event is an event handler found on JsonSerializer. The error event is raised whenever an exception is thrown while serializing or...
Read more >
Exception in JSON Deserialize - Help - UiPath Forum
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is...
Read more >
How to handle the errors generated while deserializing a ...
We can handle the errors generated while deserializing the JSON by implementing the handleUnknownProperty() method of ...
Read more >
JSON.deserialize throw exception - Salesforce Stack Exchange
JSON.deserialize throw exception ... I am trying to deserialize a string into a inner class. the I can transform that class into the...
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