Exception when deserializing from JSON
See original GitHub issueWhen 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:
Can you tell us what we’re doing wrong?
– Poke
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (15 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks! Fixed in 4.8.81.
I think you are the first users who tried to use the serialization / deserialization support 😃
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.